[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5 and tags
- From: Mike Pall <mikelu-0407@...>
- Date: Sun, 25 Jul 2004 22:49:31 +0200
Hi,
Vincent Penne wrote:
> The problem with that solution is that it complicates greatly the
> registration of functions, because you have to think in advance of all
> types that are going to be checked by your function (for example let's
> say that your function takes 10 arguments, each of different types). You
> would need to have 10 upvalues for your function, furthermore you would
> need to remember which upvalue index corresponds to which type.
Of all the Lua libraries I have come across recently, most methods need
exactly one userdata argument (i.e. 'self'). Only a few need two.
Maybe that's because 'doing it the Lua way' suggest a different API style
(e.g. using strings as options or keys, using multiple arguments instead
of wrapping them up into userdata structures).
The case you mention is somewhat common when you have to create a binding
to huge OO-style libraries that have not been designed exclusively for Lua
(GUI libraries come to mind). I'm pretty sure it pays off to autogenerate
the wrapper code in this case. Then juggling around with different metatables
and upvalues really doesn't matter. But performance does.
> However, a similar idea would be to create lua references on the
> metatables with lua_ref , then you use lua_rawequals like you suggested.
> However I have no idea of the efficiency of lua_ref / lua_getref
> functions (haven't looked at the code yet).
2* lua_rawgeti() + 2* lua_rawseti() plus a few other API calls for the
common code path in luaL_ref(). I guess this is even slower than any
of the registry approaches.
Bye,
Mike