This is my "wait.lua" file:
module (..., package.seeall)
local threads = {}
function violence_update ()
-- for each active thread, see if the time is up
for k, v in pairs (threads) do
if os.time () >= v then
threads [k] = nil -- delete from table now
assert (coroutine.resume (k))
end
end
end
function wpause (seconds)
threads [assert (coroutine.running (), "Must be in coroutine")] = os.time () + (seconds or 1)
return coroutine.yield ()
end
function make (f)
assert (type (f) == "function", "wait.make requires a function")
coroutine.wrap (f) () -- make coroutine, resume it
end -- make
-- violence_update handler insert
table.insert (handlers.violence_update, violence_update)
Inside startup.lua add "violence_update" and require:
for _, name in ipairs {
"new_player",
"entered_game",
"speech",
"entered_room",
"killed_mob",
"got_object",
"lost_object",
"looking",
"char_update",
"act",
"give",
"bribe",
"buy",
"wear",
"drop",
"repair",
"advance_level",
"use",
"violence_update" -- <----------- HERE
} do
_G [name] = MakeHandler (name) -- make a function handler
handlers [name] = {} -- make empty handlers table
end -- for loop
pause = require("wait").wpause -- insert and rename wait.wpause(vaue) to pause(value)
Once this is done we could write a function like:
function function_with_pause()
print( "Function_with_pause: start" )
wait.make( function ()
pause(3)
print( "MSG part1" )
pause(3)
print( "MSG part2" )
end
)
print( "Function_with_pause: end" )
end
I point out two completely independent things.
(1) I believe it is necessary to take care of the player_name.lua files when a character is deleted or renamed. A new character with the same name could access the old character's .lua data.
(2) for EXT_BV in lua_scripting.c it seems to me it works to do for example:
#define EXIT_EXT_BV_ITEM (arg) \
lua_pushstring (L, print_bitvector (& pexit-> arg)); \
lua_setfield (L, -2, #arg)
...so you can then use: EXIT_EXT_BV_ITEM (exit_info); |