步骤

1. 执行configure

2. 将你的bifs加入至erts/emulator/beam/bif.tab

bif re:grep/2 bif re:compile/1

3. 创建一个C代码文件

erts/emulator/beam/erl_bif_re.c

4.将你的C代码文件加入至erts/emulator/<arch>/Makefile里

RUN_OBJS = $(OBJDIR)/erl_bif_re.o \

5. implement your bifs by stealing bits from existing erl_bif_*.c files

參考其余的erl_bif_*.c文件,加入以下这段代码

1
2
3
4
5
BIF_RETTYPE re_grep_2(BIF_ALIST_2){
  Eterm result;
  result = magic_function();
  BIF_RET(result);
}

6. 执行make; make install

重点回想:

步骤0-3仅仅需执行一次,假设你将以下的bif
1
bif re:grep/2

加入至bif.tab时。erl_bif_re.c文件要实现以下这个函数

title=Adding_my_own_BIF#" class="toolbar_item command_help help" style="font-variant: inherit; color: white !important; margin: 0px !important; padding: 1px 0px 0px !important; border: 0px !important; font-size: 1em !important; vertical-align: baseline !important; text-decoration: none !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: center !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; display: block !important;">?

1
BIF_RETTYPE re_grep_2(BIF_ALIST_2);

[Erlang]怎样加入自己的BIF的更多相关文章

  1. erlang 健壮性

    erlang 提供了简单易用的并发编程模型,基本不需要再考虑多线程并发问题.但实际应用中并不是那么的完美,很多地方需要注意,就算标准库也有不少问题.很多在多线程编程中很多很容易解决的事情,在erlan ...

  2. erlang note

    没有关于erlang interface ,继续寻找吧... --------------------------------------------------------------- erl - ...

  3. Erlang数据类型的表示和实现(5)——binary

    binary 是 Erlang 中一个具有特色的数据结构,用于处理大块的“原始的”字节块.如果没有 binary 这种数据类型,在 Erlang 中处理字节流的话可能还需要像列表或元组这样的数据结构. ...

  4. erlang虚拟机代码执行原理

     转载:http://blog.csdn.NET/mycwq/article/details/45653897 erlang是开源的,很多人都研究过源代码.但是,从erlang代码到c代码,这是个不小 ...

  5. erlang判断模块导出函数问题

    erlang本身提供一个接口,可以用来检查模块是否有导出函数,这个接口是erlang:function_exported/3,但是很多时候这个接口无法正常使用. 下面重现一下这个问题: 1> e ...

  6. erlang学习笔记

    安装 Ubuntu Server上: sudo apt-get install erlang 如果安装时下载 太慢,可手工下载deb包( esl-erlang_16.a-rc1_ubuntu_prec ...

  7. [Erlang 0126] 我们读过的Erlang论文

    我在Erlang Resources 豆瓣小站上发起了一个征集活动 [链接] ,"[征集] 我们读过的Erlang论文",希望大家来参加.发起这样一个活动的目的是因为Erlang相 ...

  8. [Erlang 0119] Erlang OTP 源码阅读指引

      上周Erlang讨论群里面提到lists的++实现,争论大多基于猜测,其实打开代码看一下就都明了.贴出代码截图后有同学问这代码是哪里找的?   "代码去哪里找?",关于Erla ...

  9. [Erlang 0116] 当我们谈论Erlang Maps时,我们谈论什么 Part 1

         Erlang 增加 Maps数据类型并不是很突然,因为这个提议已经进行了2~3年之久,只不过Joe Armstrong老爷子最近一篇文章Big changes to Erlang掀起不小了风 ...

随机推荐

  1. [Unity菜鸟] Mecanim 系统遇到的问题

    1. 给角色添加一个Animator组件和New State,运行后,摆出这种奇怪的姿势 这是因为没有把动画片段赋给New State,可以看到此时的New State为空,把Idle片段拖进去就好了 ...

  2. free 命令解释

    free 命令 buffers and cached 解释 N多人总是询问,当在linux在输入free时内存总数怎么加起来不一样啊,下面我来解释一下free命令的输出. 我们运行free命令时都会看 ...

  3. Moduli number system

    A number system with moduli is defined by a vector of k moduli, [m1,m2, ···,mk]. The moduli must be p ...

  4. Micro 消息

    上周,微软与计算机历史博物馆合作,发布了MS-DOS 1.1/2.0和Word for Windows 1.1a版本的源码,这是微软首次将其核心产品开源. MS-DOS MS-DOS是微软于1981年 ...

  5. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.2

    Show that the following statements are equivalent: (1). $A$ is positive. (2). $A=B^*B$ for some $B$. ...

  6. 数组MARSHALLING z

    在托管代码和本地代码之间传递数组,是interop marshaling中间比较复杂的一个问题.本文从数组的定义开始,介绍数组marshalling的三种方法,并对blittable类型等概念做进一步 ...

  7. EF RepositoryBase 参考示例【转】

    1.定义泛型类 namespace Crm.Data.Logic.Repository{    public abstract class AbstractRepository<TC, T> ...

  8. 设计模式_Adapt

    一个形象的例子: (ADAPTER)在朋友聚会上碰到了一个美女Sarah,从香港来的,可我不会说粤语,她不会说普通话,只好求助于我的朋友kent了,他作为我和Sarah之间的Adapter,让我和Sa ...

  9. Flex 箭头(军标)库封装完成

    封装的一个月,在这个月期间还完成的一些其它的工作:公司有规定不能公布代码,我可以讲一下大致的流程,真的很抱歉! 1.用B样条曲线画箭头的两侧的曲线,这个要注意了,不要贝塞尔曲线,因为贝塞尔曲线的算法会 ...

  10. NodeJS 框架 Express 从 3.0升级至4.0的新特性

    NodeJS 框架 Express 从 3.0升级至4.0的新特性 [原文地址:√https://scotch.io/bar-talk/expressjs-4-0-new-features-and-u ...