diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-12 15:08:25 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-12 15:08:25 +0100 |
commit | 95f096e7fefd9ddb5130c1faf7314cb19922e3ad (patch) | |
tree | 097927c2b94c821521cc78bdfe59bf796c1aa5d9 | |
parent | e8bbb3ec7ef07b73e98fc535d7bd04a67c385c79 (diff) | |
download | applause2-95f096e7fefd9ddb5130c1faf7314cb19922e3ad.tar.gz |
make applause.lua reloadable using the reload() global function
-rw-r--r-- | applause.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/applause.lua b/applause.lua index 163d9e9..a822cc0 100644 --- a/applause.lua +++ b/applause.lua @@ -8,10 +8,18 @@ local C = ffi.C -- Make table.new() available (a LuaJIT extension) require "table.new" +-- Useful in order to make the module reloadable +local function cdef_safe(def) + local state, msg = pcall(ffi.cdef, def) + if not state then + io.stderr:write("WARNING: ", msg, "\n") + end +end + -- -- Define C functions for benchmarking (POSIX libc) -- -ffi.cdef[[ +cdef_safe[[ typedef long time_t; struct timespec { @@ -52,7 +60,7 @@ end -- Define the Lua FFI part of Applause's C core. -- These functions and types are defined in applause.c -- -ffi.cdef[[ +cdef_safe[[ enum applause_audio_state { APPLAUSE_AUDIO_OK = 0, APPLAUSE_AUDIO_INTERRUPTED, @@ -86,6 +94,13 @@ function msec(x) return sec((x or 1)/1000) end -- false. local clock_signal = false +-- Reload the main module: Useful for hacking it without +-- restarting applause +function reload() + dofile "applause.lua" + collectgarbage() +end + -- FIXME: Inconsistent naming. Use all-lower case for functions -- and methods? function DeriveClass(base) @@ -1673,7 +1688,7 @@ end -- and works only with clients created via Stream.fork() -- -ffi.cdef[[ +cdef_safe[[ int kill(int pid, int sig); ]] |