lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Dušan Majkić wrote:
> I was hoping for something like:
> lua_register_via_FFI(my_nonlua_func, "int my_nonlua_func(int s, const
> char *m)");
> or FFIs bulk register, like luaL_register.

Create a record with function/procedure pointers and initialize it
with your exported functions. Then pass the address of that record
as a lightuserdata to Lua.

On the Lua side, declare an equivalent C struct containing
function pointers. Then use ffi.cast to cast the lightuserdata
object into a pointer to this struct. Store it somewhere and then
use it like 'y = +' from then on.

> I'm using Lua in delphi app,
> and there is no way to export functions from exe project.

According to a short search, there is a way to do that: edit the
.DPR and add an explicit 'exports' clause, listing all exported
functions. I think this is easier than the above.