Special indices (was Re: Simple C++ wrapper)
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Special indices (was Re: Simple C++ wrapper)
- From: Mark Hamburg <mark@...>
- Date: 2009年4月25日 15:48:08 -0700
This reminds me of an issue I ran into when considering a Lua patch to
provide fast access to the environment table for userdata objects
(more below), LUA_REGISTRYINDEX is both the index used to access the
registry and the boundary for the special indices. It would be nice to
have a separate #define for the latter -- e.g., LUA_MINSTACKINDEX-- so
that when adding new special indices code that needs to know where the
stack indices end (particularly the negative indices) would be updated
on a recompile. With that in place, the below code would become:
if(index < 0 && index >= LUA_MINSTACKINDEX)
index -= 1;
Actually, it might be useful to simply pre-reserve some expansion
space though that assumes that nothing else in a release would force a
recompile.
Mark
P.S. The specific case that triggered this thinking for me was around
adding LUA_UDENVINDEX which is defined as pointing to the environment
table of the userdata value at index 1. It results in an error if
index 1 does not contain a full userdata. Its intended use is to make
it easier to create userdata objects that use their environment tables
to store references to other Lua objects -- e.g., lua_getfield(L,
LUA_UDENVINDEX, "on_click").
On Apr 24, 2009, at 1:17 PM, TNHarris wrote:
Hello,
I'd like to wrap the Lua API in a C++ class to take advantage of
overloading and default arguments, etc. I looked at Paolo Capriotti's
library but it seems to be oriented for using C++ objects on the
stack.
I don't need that so much as just a more convenient way to use Lua.
I think something like this would be favorable:
namespace luaxx
{
class State
{
void getTable(int index = -2)
{ lua_gettable(m_L, index); };
void getTable(int index = -2, int key = -1)
{
if (index < 0 && index > LUA_REGISTRYINDEX)
index -= 1;
push(key);
lua_gettable(m_L, index);
};
};
}
Does anyone have a library already made?
-- tom
telliamed@whoopdedo.org