lua-users home
lua-l archive

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


Getting the function name from Lua is O(1).  I cheated and modified Lua to
store the last function called on a global stack.  Then, when I get to the
callback handler, I pop the top off of the stack

As far as looking up the function, I don't even bother with a hash table.
The search time is Log(num_exported_functions). which is going to be small
all things considered.

I have not done any direct timings, but I am using it in a 3d engine
(LithTech) and even calling Lua every frame isn't costing me more than a
frame or two a second.  I usually call it far less frequently that that, but
I have not found any of my speed problems in the Lua code yet, and I am not
even using the latest version, which from what I understand is about 10-15%
faster.

The argument validation is extremely useful because it even validates the
types of userdata returned from Lua.


--Jens Wessling

As far

> > The short answer is FuBi, or Function Binding Interface.  I
> > first found out about it in an article in Game Programming
> > Gems by Scott Bilas.  He presented it at GDC 2001 and he has
> > information on it on his website as well.  It parses export
> > information from the binary file (EXE or DLL), demangles the
> > function names, and parses the function definition in to a
> > database along with the pointer to the location of the
> > function in memory. The lookup is a simple search of the
> > database for a matching function name. (Database is a bit of
> > an exaggeration, it is just a std::set<> of function
> > definitions).  My callback function hand builds the call
> > stack, then I jump to the right location in memory.  There
> > are a lot of little issues involved with this, if anyone
> > wants more information, feel free to contact me offline.
>
> So, basically, Lua does a hashed lookup to get to your callback function
> and then you do another lookup to get to the right function (by querying
> the Lua call stack for the name?).  Sounds time intensive, although the
> verification of arguments sounds like a very good thing.
>
> Do you have any speed measurements?
>
> Thanks,
> Josh