1 /* 2 * SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com> 3 * 4 * SPDX-License-Identifier: LGPL-2.1-or-later 5 * 6 */ 7 #include "luahelper.h" 8 #include "luaaddonstate.h" 9 10 namespace fcitx { 11 12 FCITX_DEFINE_LOG_CATEGORY(lua_log, "lua"); 13 14 decltype(&::lua_getglobal) _fcitx_lua_getglobal; 15 decltype(&::lua_touserdata) _fcitx_lua_touserdata; 16 decltype(&::lua_settop) _fcitx_lua_settop; 17 decltype(&::lua_close) _fcitx_lua_close; 18 decltype(&::luaL_newstate) _fcitx_luaL_newstate; 19 GetLuaAddonState(lua_State * lua)20LuaAddonState *GetLuaAddonState(lua_State *lua) { 21 _fcitx_lua_getglobal(lua, kLuaModuleName); 22 LuaAddonState **module = 23 reinterpret_cast<LuaAddonState **>(_fcitx_lua_touserdata(lua, -1)); 24 _fcitx_lua_settop(lua, -2); 25 return *module; 26 } 27 28 } // namespace fcitx 29