diff options
Diffstat (limited to 'generator/lua.ml')
-rw-r--r-- | generator/lua.ml | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/generator/lua.ml b/generator/lua.ml index 2b3e4a57..603b396c 100644 --- a/generator/lua.ml +++ b/generator/lua.ml @@ -676,6 +676,16 @@ push_int64_array (lua_State *L, const int64_t *array, size_t len) (* Code to handle events. *) pr "\ +static const char *event_all[] = { +"; + + List.iter ( + fun (event, _) -> pr " \"%s\",\n" event + ) events; + + pr " NULL +}; + static uint64_t get_event_bitmask (lua_State *L, int index) { @@ -699,18 +709,9 @@ get_event_bitmask (lua_State *L, int index) static uint64_t get_event (lua_State *L, int index) { - const char *s; - - s = luaL_checkstring (L, index); -"; + int r = luaL_checkoption (L, index, NULL, event_all); - List.iter ( - fun (event, i) -> - pr " if (strcmp (s, \"%s\") == 0)\n" event; - pr " return %d;\n" i - ) events; - - pr " return luaL_error (L, \"unknown event name '%%s'\", s); + return UINT64_C(1) << r; } static void @@ -729,16 +730,6 @@ push_event (lua_State *L, uint64_t event) pr " abort (); /* should never happen */ } -static const char *event_all[] = { -"; - - List.iter ( - fun (event, _) -> pr " \"%s\",\n" event - ) events; - - pr " NULL -}; - "; (* Code to push structs. *) |