[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: void* in Lua_State for Application?
- From: Jean-Luc Jumpertz <jean-luc@...>
- Date: Mon, 2 Sep 2013 15:01:39 +0200
Le 2 sept. 2013 à 14:27, Roberto Ierusalimschy <roberto@inf.puc-rio.br> a écrit :
>> Lua team, could you consider adding this call to luai_userstatefree in function close_state for a next version of Lua ? ;-)
>
> There is already a "call" to luai_userstateclose in lua_close.
Hi Roberto,
You're right, luai_userstateclose is just appropriate for releasing/freeing the private pointer associated to the main thread.
I don't know how I could have missed it...
So the addition to luaconf.h becomes:
-<<
/*
@@ LUA_EXTEND_STATE controls the definition of a private buffer in lua_State.
** CHANGE it (define it) and put your private details in an external file if
** you want Lua to use this feature
*/
#if defined(LUA_USER_STATE)
// Define the user part of a lua_State strcture: all we need here is a single void* pointer to our private thread object
#define LUAI_EXTRASPACE sizeof(void *) /* or the size of your custom state */
#define luai_userstate(L) ((void**)(((unsigned char *)L) - LUAI_EXTRASPACE))
/* Note that the lua_State type is not define at this stage, so we pass void* to the functions instead */
extern void CLDVLuaUserStateOnLuaNewState (void *L);
extern void CLDVLuaUserStateOnLuaNewThread (void *L, void *newL);
extern void CLDVLuaUserStateOnLuaFreeState (void *L, void *freedL);
/* Called in lua_newstate */
#define luai_userstateopen(L) (CLDVLuaUserStateOnLuaNewState(L))
/* Called in lua_close */
#define luai_userstateclose(L) (CLDVLuaUserStateOnLuaFreeState(NULL, L))
/* Called in lua_newthread */
#define luai_userstatethread(L,L1) (CLDVLuaUserStateOnLuaNewThread(L,L1))
/* Called in luaE_freethread (by GC) */
#define luai_userstatefree(L,L1) (CLDVLuaUserStateOnLuaFreeState(L,L1))
#endif
->>
And no change needs to be done to the Lua source code. :-)
Jean-Luc