lua-users home
lua-l archive

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


On Mon, Mar 7, 2011 at 6:59 PM, Drake Wilson <drake@begriffli.ch> wrote:
Quoth Chris Gagnon <cgagnon@zindagigames.com>, on 2011-03-07 17:32:30 -0800:
> All my lua runs in environments that contain an ID.
>
> here is the c:
> int SomeFuncImplementation(lua_State * L)
> {
>    // I need the ID
>    // How do i get it!?
>
>    // This doesn't work because it's the environment of this c function
> which is useless to me
>    lua_getfield(L, "ID", LUA_ENVIRONINDEX);
>
>   // lua_getfenv() is useless cause i can't get the calling function on the
> stack to use this
> }

Where is this ID exactly?  Could you describe the relation between the
environments in question (by which I assume you mean environment
tables associated with functions) and the call stack you're looking
at?  In particular, is there a reason you can't pass the ID down as an
ordinary parameter?

> - Chris

  ---> Drake Wilson

The ID is just a piece of data important for code on the c side that needs it to track things.
You are correct i am referring to environment tables associated with the functions, 
i have many environments they act as sandboxes for individual scripts to run in.
The ID is just unique number i use to track things on the c side.
I don't see what the stack really has to do with this, the issue exists anytime lua calls into a c function.

I don't want users to have to pass the ID to every function that needs it. Users shouldn't have to worry about it.

store a pointer to your environment in the registry

How does this even work, there are many environments and only one registry.
I would not know which one was used by the calling code.

- Chris