[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Dynamically create Lib?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 15 Oct 2013 15:00:27 -0300
> Is it possible to dynamically register C functions in Lua?
>
> Pseudocode:
>
> add_function_to_lua(lua_State *L, char *libname, char *fname, int (*func)(lua_State *)) {
> struct luaL_reg *reg = malloc(sizeof(*reg));
> reg->name = fname;
> reg->func = func;
>
> luaL_register(L, libname, reg);
lua_getglobal(L,libname);
lua_pushcfuntion(L,func);
lua_setfield(L,fname);
lua_pop(L,1); /* remove library from stack when done */