lua-users home
lua-l archive

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

>Yesterday I tried to write a C function ImportSystem() which uses
>lua_register() to make some functions available for my scripts. I
>planned to export ImportSystem() itself, so each script that needs to
>use the System-library could call it. Because LuaC also compiles scripts
>without knowing which functions exist and which not, I thought maybe Lua
>checks for a symbol just before it is called. Well, it doesn't.

luac uses exactly the same parser and code generator as lua does.
In any case, everything in Lua is dynamic, so nothing is checked at compile

I didn't understand your problem very well, but if you want to register
functions by demand, then you could do the following:
Set a "getglobal" tag method for tag(nil) to just return the name of the
Set a "function" tag method for tag"" to check whether the name is know,
and in this case call ImportSystem(). Perhaps it is simpler to write
this "function" tag method in C; the code would then look for the name in
a static table in C. If it is found, then register the function with the
given name and return this Cfunction.
There is no performance hit after the first time, so it's trully by demand.

I hope this helps. This could be considered a Lua idiom...