#ifndef PKGIT_LUA_STATE_H #define PKGIT_LUA_STATE_H #include #include #include #include extern lua_State *L; extern bool L_is_loaded; bool init_lua_state(void); bool init_lua_config(void); void free_lua_state(void); void free_lua_config(void); #define lua_get_field_type(name, type, file, pop_num) \ do { \ lua_getfield(L, -1, name); \ if (!lua_is##type(L, -1)) { \ log_error("lua: expected type '" #type "' for '%s' in '%.*s'", \ name, str_fmt(file)); \ lua_pop(L, pop_num); \ return false; \ } \ } while (0) #define lua_get_table(name, file, pop_num) \ do { \ lua_pushstring(L, name); \ lua_gettable(L, -2); \ lua_pop(L, 1); \ if (!lua_istable(L, -1)) { \ log_error("lua: expected type 'table' for '%s' in '%.*s'", \ name, str_fmt(file)); \ /*lua_pop(L, pop_num);*/ \ return false; \ } \ } while (0) #define lua_run_function(name, file, params, returns, pop_num) \ do { \ if (lua_pcall(L, params, returns, 0)) { \ log_error("lua: '%s' function borked in %.*s: %s", \ name, str_fmt(file), lua_tostring(L, -1)); \ lua_pop(L, pop_num); \ return false; \ } \ } while (0) #endif