lua-users home
lua-l archive

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


>Why do you want the C code to bother with global names? 

In this specific case, because I don't want Lua to do anything 
functional aside from act as a data description language that can be 
queried from C.  Since this is one of Lua's main touted strengths, I 
had hoped it wasn't something TOO far fetched =)

>Better to do that stuff in Lua and just pass necessary data to C
>functions (as table references). 

Maybe there is a better way, and I'd love to see it.

I'm currently using Lua in a "pull model", where C pulls data from 
the Lua subsystem.  A trivial but common example of this is where you 
have a Quake-style cvar system where named variables exist in the 
global Lua namespace and the application may want to query this 
information.

For example, you may have a client side cvar that determines if you 
should render in wireframe.  The way you would do this in a 
pull-model is to do something like this:

bool wireframe = lua.getValue( "/r_wireframe/value" ) != 0.0f;

Then the rendering engine can query this value as above.

This seems completely reasonable to me.  I like having my cvars 
within the Lua space, because then I can trivially archive my entire 
cvar state to disk and reload it with a loadstring/dobuffer or 
whatever it's called now =)

The push-model system has Lua controlling this by calling into the 
engine to enable/disable wireframe rendering, and the engine itself 
knows nothing about Lua.  This is equally valid, but it's heavier 
weight since I now I have to export functions to Lua instead of just 
having a generic data query.

Brian