c_func
| Definition: | atom res = c_func(integer rid, sequence args={}) |
| Description: |
Call a C function.
rid must be a result from define_c_func(). args is a sequence of argument values of length n, where n is the number of arguments required by the function. res will be the result returned by the C function. |
| pwa/p2js: | Not supported. |
| Comments: |
If the C function does not take any arguments then args should be {}.
If you pass an argument value which contains a fractional part, where the C function expects a C integer type, the argument is rounded towards 0, for example 5.9 is passed as 5, -5.9 is passed as -5. The C function could be part of a .dll or .so created via a format DLL/SO directive. NB: While call_func(id,args) can now be invoked via id(args), you cannot replace c_func(rid,s) with rid(s). |
| Example: |
atom hwnd, ps, hdc
atom user32 = open_dll("user32.dll")
-- the C function BeginPaint takes a C int argument and
-- a C pointer, and returns a C int as a result:
integer BeginPaint = define_c_func(user32, "BeginPaint", {C_INT, C_PTR}, C_INT)
-- call BeginPaint, passing hwnd and ps as the arguments,
-- hdc is assigned the result:
hdc = c_func(BeginPaint, {hwnd, ps})
|
| Implementation: | See builtins\VM\pcfunc.e (an autoinclude) for details of the actual implementation. |
| See Also: | c_proc, define_c_func, open_dll, Calling C Functions |