From 7758311f88255eda1f37c1ad641964d50f5d5a79 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 2 Apr 2015 16:55:27 -0400 Subject: [PATCH] Make gametype functions use default arguments when called from Lua --- library/LuaApi.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index f7de14876..ee2ca3702 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1770,10 +1770,29 @@ static const LuaWrapper::FunctionReg dfhack_world_module[] = { WRAPM(World, ReadCurrentWeather), WRAPM(World, SetCurrentWeather), WRAPM(World, ReadWorldFolder), - WRAPM(World, isFortressMode), - WRAPM(World, isAdventureMode), - WRAPM(World, isArena), - WRAPM(World, isLegends), + { NULL, NULL } +}; + +#define WORLD_GAMEMODE_WRAPPER(func) \ + static int world_gamemode_##func(lua_State *L) \ + { \ + int gametype = luaL_optint(L, 1, -1); \ + lua_pushboolean(L, World::func((df::game_type)gametype)); \ + return 1;\ + } +#define WORLD_GAMEMODE_FUNC(func) \ + {#func, world_gamemode_##func} + +WORLD_GAMEMODE_WRAPPER(isFortressMode); +WORLD_GAMEMODE_WRAPPER(isAdventureMode); +WORLD_GAMEMODE_WRAPPER(isArena); +WORLD_GAMEMODE_WRAPPER(isLegends); + +static const luaL_Reg dfhack_world_funcs[] = { + WORLD_GAMEMODE_FUNC(isFortressMode), + WORLD_GAMEMODE_FUNC(isAdventureMode), + WORLD_GAMEMODE_FUNC(isArena), + WORLD_GAMEMODE_FUNC(isLegends), { NULL, NULL } }; @@ -2635,7 +2654,7 @@ void OpenDFHackApi(lua_State *state) OpenModule(state, "units", dfhack_units_module, dfhack_units_funcs); OpenModule(state, "items", dfhack_items_module, dfhack_items_funcs); OpenModule(state, "maps", dfhack_maps_module, dfhack_maps_funcs); - OpenModule(state, "world", dfhack_world_module); + OpenModule(state, "world", dfhack_world_module, dfhack_world_funcs); OpenModule(state, "burrows", dfhack_burrows_module, dfhack_burrows_funcs); OpenModule(state, "buildings", dfhack_buildings_module, dfhack_buildings_funcs); OpenModule(state, "constructions", dfhack_constructions_module);