[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua Pre-compiler / Lua side userdata
- From: Patrick Donnelly <batrick@...>
- Date: Mon, 12 Oct 2009 15:38:07 -0400
On Mon, Oct 12, 2009 at 3:30 PM, Chris Gagnon <firstname.lastname@example.org> wrote:
> I'm come to a situation, where to maintain readability for script writers
> but ensure fast code i want to parse lua code before it goes to the
> The issue i foresee is that I'll essentially want to create user data in the
> Lua script.
> So an example in Lua:
> very readable, however strings...yuck
> I want to create a hash of that string for speed:
> PostEvent( 0xABC45678 )
> All is good you might think, however the gotcha is that that we compile lua
> using a 32-bit float to represent numbers.
> Internally that float will lose the precision and hence mess up the 32 bit
> Basically I'm looking for any suggestions, as i don't have any great ideas
> that don't add needless run time overhead.
Create a table on the C side that maps strings to a C enum. Add a
string -> enum mapping for all option strings. Then during runtime,
you simply index the option string (passed from Lua) into the table
and use the integer (enum) value for whatever (if you get nil, then
they passed a bad string).
"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."
- Benjamin Franklin