lua-users home
lua-l archive

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


On Friday 05 February 2010, Joshua Jensen wrote:
> By storing the lua_TValue locally, it provides the fastest possible
> access to the data being stored.  It is as if LuaPlus's C++ LuaObjects
> extend the Lua stack into C++ objects.

I see: the access is as fast as possible because it doesn't go through the 
stack-based C-API (e.g. index2adr within lua_istable) instead it uses direct 
access to the object structure (e.g.ttype(&m_object) == LUA_TTABLE).

> The LuaObjects are marked during the garbage collector's markroot() and
> atomic() runs.
> With just a cursory glance, all I really need to pull this off is a user
> garbage collection callback called at the markroot() and atomic()

As I understand it: there is a linked-list of used objects and these are 
considered at the beginning of garbage collection?

So it seems that access via LuaObject is very fast but there comes some 
overhead in creating, copying and destroying the LuaObjects. Did you try to 
measure timing how much this solution is in overall performance better than 
using the stack based C-API interface?

> What I want to do is fix luaL_ref() to be fast.  I don't really want to
> modify the Lua core, but I want access to saved off Lua values to be
> faster than it currently is.  Lua 4.0 or 4.1, I believe, had a more
> efficient lua_ref() for my usage patterns.  If luaL_ref() was more
> efficient, then a LuaPlus::LuaObject() would just wrap that.

So do you mean, that if the registry access would be faster than you would 
store every LuaObject into the registry and then work with the stack-based C-
API? But then you wouldn't have the performance of directly accessing the lua 
objects. Or do you just want to have to object in the registry to prevent 
garbage collection and still using the lua_TValue inside LuaObject?

> That doesn't directly answer your question, but it does show that I'd
> like some modifications to be able to use a standard Lua core with the
> C++ classes I maintain.

So at least I'm not the only person thinking that some enhancements in the 
official Lua C-API could it make easier to access Lua from C++ ;-)

Best regards,
Oliver