[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Optimizing variable access from C
- From: David Jones <drj@...>
- Date: Thu, 21 Feb 2002 11:22:33 +0000
In message <BCF3A47F02AB8643BB391B0517EBD6440394ECE6@red-msg-08.redmond.corp.mi
crosoft.com>, "Curt Carpenter" writes:
> > How about doing it other way around? I.e. storing the variables in C
> and accessing them with set/get functions from Lua?
>
> Then I have to have some sort of reverse string lookup table
> (duplicating what Lua already does), which seems about as expensive (and
> more complex).
Store your variable in C. EG
float coolParm1;
For each different C type you use you'll need a new tag.
Create a lua userdata object with the appropriate tag that points to the C
variable:
lua_pushusertag(L, &coolParm1, myFloatTag);
Bind this value to a lua global variable:
lua_setglobal(L, "coolParm1");
Define a getglobal and setglobal tag method for myFloatTag that
translates the representation in C into a representation in lua. In the
case of float this is obvious.
Now you can access the C variable from lua transparently.
I'm sure that's what the original respondent had in mind.
Cheers,
drj