lua-users home
lua-l archive

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

> That's a good idea. But why is the registry less efficient? 
> Can't you store a string in the registry and get back a 
> numeric id that can be handed back to the registry to get 
> pushed just as fast as an upvalue? Or is there some 
> optimization in upvalues that make them faster?

In LuaPlus, this is done very efficiently and looks like this:

LuaObject string1;
LuaObject string2;

string1.AssignString(state, "Hello");
string2 = state->GetGlobal("SomeEntryThatEqualsHello");

if (string1 == string2)

LuaObjects can persist as globals variables, so I frequently optimize by
grabbing as many of the known strings in advance and using them to index

Interestingly, LuaRC is missing an API for it, but it would easily support
incrementing the reference count on the object and holding onto it that