Adding my own BIF

From Erlang Community

(Difference between revisions)
Revision as of 17:11, 31 July 2006 (edit)
Massemanet (Talk | contribs)

← Previous diff
Current revision (17:13, 31 July 2006) (edit) (undo)
Massemanet (Talk | contribs)

 
Line 1: Line 1:
 +===caveat===
 +unless you really know what you're doing, you'll be better off using a linked-in driver or a port.
===steps=== ===steps===
:1. run configure :1. run configure
Line 38: Line 40:
BIF_RETTYPE re_grep_2(BIF_ALIST_2); BIF_RETTYPE re_grep_2(BIF_ALIST_2);
</pre> </pre>
-*unless you really know what you're doing, you'll be better off using a linked-in driver or a port. 
[[Category:HowTo]] [[Category:HowTo]]

Current revision

[edit] caveat

unless you really know what you're doing, you'll be better off using a linked-in driver or a port.

[edit] steps

1. run configure
2. add your bifs to erts/emulator/beam/bif.tab

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

3. create a C file

erts/emulator/beam/erl_bif_re.c

4. add your C file to erts/emulator/<arch>/Makefile

RUN_OBJS = $(OBJDIR)/erl_bif_re.o \

5. implement your bifs by stealing bits from existing erl_bif_*.c files
BIF_RETTYPE re_grep_2(BIF_ALIST_2){
  Eterm result;
  result = magic_function(); 
  BIF_RET(result);
}
6. run make; make install

[edit] notes

  • steps 0-3 need only be done once.
  • note that if you add
bif re:grep/2

to bif.tab there should be a erl_bif_re.c that implements

BIF_RETTYPE re_grep_2(BIF_ALIST_2);
Erlang/OTP Projects
Personal tools