summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-20 09:10:15 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-20 09:10:15 +0000
commitb5b475ab827b862cce07ab095e4cb8b4ab1a954a (patch)
treed5f743a360a5ee756e726d061bf4bd356622afb0
parentfdfdc883fcac8c8d7e4e9a86572d941421b5ff87 (diff)
downloadlibguestfs-b5b475ab827b862cce07ab095e4cb8b4ab1a954a.tar.gz
libguestfs-b5b475ab827b862cce07ab095e4cb8b4ab1a954a.tar.xz
libguestfs-b5b475ab827b862cce07ab095e4cb8b4ab1a954a.zip
lua: Simplify get_event function.
Use luaL_checkoption which is designed for this purpose.
-rw-r--r--generator/lua.ml33
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. *)