lua-users home
lua-l archive

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


I find myself making this modification to the Lua state structure a lot,
so maybe it is a feature worth adding.

I work with context based libraries, so I need access to a user definable context
in my Lua c wrappers, through the Lua state, the access to which needs to be 
very fast.

My proposal is a simple user definable void* pointer in the Lua state, with 
set and get API calls:

void lua_setuserctx( lua_State * pL, void* p )
{
    pL->userctx = p;
}

void* lua_getuserctx( lua_State * pL )
{
    return pL->userctx;
}

So you would then have access to your program's context in your 
lua c wrappers -

static int cwrapperfunction( lua_State * pL )
{
    MyLibContext * ctx = ( MyLibContext* ) lua_getuserctx( pL );
    ..
}

I know you can accomplish the same with standard lua calls available
but as far as I understand it, this would always require a hash lookup. (?)
I prefer something faster and more direct.

Regards,
Jim