#define with lua

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

#define with lua

Denis Lamarche
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?

Denis

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


rje
Reply | Threaded
Open this post in threaded view
|

Re: #define with lua

rje
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.

Reply | Threaded
Open this post in threaded view
|

Re: #define with lua

Ivan Kolev-3
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

[hidden email] 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.