lua-users home
lua-l archive

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


On Saturday 06 March 2010, Alexey Baskakov wrote:
> How to add custom per-thread data in Lua 5.2?
> But I need it to be very _fast_.

In Lua 5.1 there are the following macros in luaconf.h. With these macros you 
can put extra data to any Lua state and it will be very fast. However you have 
to compile your own Lua interpreter, so I'm not sure if this is what you are 
looking for:

- LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
  (the data goes just *before* the lua_State pointer).

- luai_userstate* allow user-specific actions on threads.
  CHANGE them if you defined LUAI_EXTRASPACE and need to do something
  extra when a thread is created/deleted/resumed/yielded.

	luai_userstateopen(L)		((void)L)
	luai_userstateclose(L)		((void)L)
	luai_userstatethread(L,L1)	((void)L)
	luai_userstatefree(L)		((void)L)
	luai_userstateresume(L,n)	((void)L)
	luai_userstateyield(L,n)	((void)L)

In Lua 5.2 these macros are not any longer in luaconf.h but are still in the 
code: see llimits.h and lstate.c.

I hope that this mechanism will not vanish in the final Lua 5.2 version.

Best regards,