codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include "safx.h" int add(int a, int b){ return a+b; } int sub(int a, int b){ return a-b; } int sum(int argc, int *argv, int self){ int *ed = argv + argc, ret = 0; while(argv != ed) ret += *argv++; return ret; } USEFUNC(imported){ this_is_a_usefunc; //way #1 module(A) def("self.add", add) def("self.sub", sub) defva("self.sum", sum) end //way #2 define_module(B); define_module_function("B", "add", add, 2); define_module_function("B", "sub", sub, 2); define_module_function("B", "sum", sum, -1); //way #3 klass(SAFXString) function(initialize) writef("@handle = SAFX.callproc(%d).call\n", SAFXString_new); end function(append(str)) writef("SAFX.callproc(%d).call(@handle, str)\n", SAFXString_append); end function(sprintf(*a)) writef("SAFX.callproc(%d).call(a.length, a.map{|x| SAFX.to_ptr(x)}.pack('L*'), @handle )\n", SAFXString_sprintfvargs); end function(length) writef("SAFX.callproc(%d).call(@handle)\n", SAFXString_length); end function(to_s) writef("SAFX.readmem(SAFX.callproc(%d).call(@handle),SAFX.callproc(%d).call(@handle))\n", SAFXString_c_str, SAFXString_length); end function(inspect) writef("Kernel.sprintf('<#%%s:%#p @handle=%#p>', self.class.to_s, self.object_id*2, @handle)\n"); end function(dispose) writef("SAFX.callproc(%d).call(@handle)\n", SAFXString_dispose); end end //strbuf end_usefunc; }
Private
[
?
]
Run code
Submit