lua-users home
lua-l archive

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



> On Behalf Of Edgar Toernig
> Sent: Friday, August 27, 2004 7:06 PM
> 
> Nick Trout wrote:
> >
> > If I have a list of functions to register in C this amounts to
something
> > _like_:
> >
> > // C
> > Lua_function_info fns[] = {
> > 	{ "ThisFunctionNameIsVeryDescriptive1", myFnCallback1 },
> > 	{ "ThisFunctionNameIsVeryDescriptiveN", myFnCallbackN },
> > 	{ 0, 0 }
> > };
> >
> > lua_register_list(fns);
> >
> > So we end up with duplicate copies of all those strings (because Lua
> > copies the function name) and closures around the C functions (32
bytes
> > each). I can't register these as local variables (so they're
indexed) so
> > I can't get the space back. (Perhaps I could somehow register them
> > through the debug library?)
> 
> /* C side */
> int
> gimme_funcs(lua_State *L)
> {
>     lua_pushcfunction(L, myFnCallback1);
>     lua_pushcfunction(L, myFnCallbackN);
>     return 5;
> }
>     ...
>     lua_register(L, "gimme_funcs", gimme_funcs);
>     ...
> 
> -- lua side
> 
> local
>   ThisFunctionNameIsVeryDescriptive1,
>   ThisFunctionNameIsVeryDescriptiveN = gimme_funcs()
> 
> But don't forget to strip debug infos...

I can see how this saves the strings, but we still have a C function
closure for every function instance (32 bytes). I guess this method is
more transparent than the method I suggested as you don't have to
pre-process the function calls. 

Nick