lua-users home
lua-l archive

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


>From: Steve Dekorte <steve@dekorte.com>
>
>What's the easiest way to register Lua C interfaces/libraries into a table instead of into globals? For instance, when calling:
>
>    mathlib_open ();
>
>I'd like the math functions to be put into a global table called "math". 
>(Or maybe under the path system.math, etc)

before calling mathlib_open, set up a "setglobal" tag method to redirect
all function definitions.

something like this:

  settagmethod(tag(nil),"setglobal", function (x,v) math[x]=v end)

after you're done, restore the old "setglobal" tag method.
if you want to keep the global names, add "rawsetglobal(x,v)" to the code above.
--lhf