lua-users home
lua-l archive

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


I was thinking of using  lua_sethook() to call a function
that checks how how much time has elapsed since the
hook was set. I was intending to use this as a kill the
thread when it has been running for too long. So I need
to keep a start time variable e.g. time_t start = time();

The lua_sethook() function does not let me pass this value
so the only way I can store the start time is in Lua, I cant
see how to store in C in a re-entrant(threadsafe) manner.
I would like keep the time on the C side to save the table
lookup on each hook call, Does anyone have a good way
of doing this without using static or global variables or C++?

And maybe in 5.2 could the prototype maybe be change from

int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);

to

int lua_sethook (lua_State *L, lua_Hook func, void* userdata, int
mask, int count);

have the hook function as

typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar, void* userdata);

Or is this change not required and is their an easier way to get
C side data into a hook function?

DB