#include #include #include #include #include "xlua.h" void pushtable(lua_State *L, const struct key *keys, ...) { va_list ap; int narr = 0, nrec = 0; for (const struct key *key = keys; key->type != KT_NULL; key++) { switch (key->type) { case KT_STRING: nrec++; break; case KT_NUMBER: narr++; break; default: luaL_error(L, "pusharray failed: key: invalid key type"); } } lua_createtable(L, narr, nrec); va_start(ap, keys); for (const struct key *key = keys; key->type != KT_NULL; key++) { switch (key->type) { case KT_STRING: lua_pushstring(L, key->key.str); break; case KT_NUMBER: lua_pushnumber(L, key->key.num); break; } switch (key->vtype) { case VT_STRING: lua_pushstring(L, va_arg(ap, const char *)); break; case VT_NUMBER: lua_pushnumber(L, va_arg(ap, lua_Number)); break; case VT_BOOLEAN: lua_pushboolean(L, va_arg(ap, int)); break; default: luaL_error(L, "pusharray failed: key: invalid value type"); } lua_settable(L, -3); } va_end(ap); } void pushsetmember(lua_State *L, int index, const char *name, bool in_set) { if (!in_set) return; if (index < 0) index -= 1; lua_pushboolean(L, 1); lua_setfield(L, index, name); }