lua-users home
lua-l archive

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


I use a macro to export C constants to Lua like this:

#define lua_setConst(name) { lua_pushnumber( name ); lua_setglobal(
#name ); }

Then for each C library I have a Lua initialization function which
registers all need C functions and constants with Lua like this:

int LibInitLua() {
	// ... export C functions

	// export C constants
	lua_setConst( RED_DOOR );
	return 1;
};

static int libInit = LibInitLua();

Then I can use RED_DOOR in Lua just as in C.

Regards,
Ivan

rjek@digital-scurf.org wrote:
> 
> On Sun, Jan 21, 2001 at 06:03:21PM -0000, Denis Lamarche wrote:
> > Is it possible to use the "C"  #define statemant in lua?
> > what I am trying to do is this (Im using uncompiles scripts)
> >
> > --Lua script
> > #define RED_DOOR   145765
> > #denine GREEN_DOOR 278434
> > #define COW        445753
> >
> > Load_Animation(RED_DOOR)  --These are "c" functions made available
> > Load_Animation(GREEN_DOOR)--to lua
> > Load_Animation(COW)
> >
> > How can I do this without pre-compilling the script files?  I was thinking
> > maybe adding RED_DOOR as a lua variable, but I will have alot of these
> > #defines as much as 1024.
> > Any Idea's?
> 
> Generally, using RED_DOOR = 145765; is much better than using #defines.  I'm
> sure I'm not on my own in not wanting such a command in Lua.
> 
> --
> Rob Kendrick - http://www.digital-scurf.org/
> You're ugly and your mother dresses you funny.