[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Optimizing variable access from C
- From: "Curt Carpenter" <curtc@...>
- Date: Thu, 21 Feb 2002 09:47:45 -0800
Perhaps I didn't describe my problem well enough. Let me try again.
I have various loosely defined "types" of tables. By a "type" I simply
mean that when a table is passed to certain functions, the function
processing the table expects certain keys to exist in the table. The
keys are well-known and fixed, i.e. field names. Now I have no control
(nor want to) over where the table is created, so I need to support
tables created in Lua. It just seems that if I know I'm looking for
fields "field1", "field2", etc. it's a waste to have to do a bunch of
string processing when I want to get to the well-known members in a
table passed into C. Does that make sense? Thanks.
From: David Jones [mailto:firstname.lastname@example.org]
Sent: Thursday, February 21, 2002 3:23 AM
To: Multiple recipients of list
Subject: Re: Optimizing variable access from C
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
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
lua_pushusertag(L, &coolParm1, myFloatTag);
Bind this value to a lua global variable:
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.