From 5fd50fea134eb3dc79bf27c8b085850ebf99295e Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sun, 1 Nov 2009 11:05:27 +0000 Subject: [PATCH] Split code a bit. --- src/scripting/lua.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index d8fa1b531eb..b891ced5d89 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -113,6 +113,17 @@ static void chat_message(std::string const &caption, std::string const &msg) events::chat_handler::MESSAGE_PUBLIC, false); } +/** + * Pushes a config as a volatile vconfig on the top of the stack. + */ +static void luaW_pushvconfig(lua_State *L, config const &cfg) +{ + new(lua_newuserdata(L, sizeof(vconfig))) vconfig(cfg, true); + lua_pushlightuserdata(L, (void *)&vconfigKey); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_setmetatable(L, -2); +} + /** * Pushes a t_string on the top of the stack. */ @@ -966,10 +977,7 @@ static int cfun_wml_action_proxy(lua_State *L) config cfg; if (!luaW_toconfig(L, 1, cfg)) goto error_call_destructors; - new(lua_newuserdata(L, sizeof(vconfig))) vconfig(cfg, true); - lua_pushlightuserdata(L, (void *)&vconfigKey); - lua_rawget(L, LUA_REGISTRYINDEX); - lua_setmetatable(L, -2); + luaW_pushvconfig(L, cfg); break; } case LUA_TUSERDATA: