MCPcopy Create free account
hub / github.com/DFHack/dfhack / open_lua

Method open_lua

library/PluginManager.cpp:802–850  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

800}
801
802void Plugin::open_lua(lua_State *state, int table)
803{
804 table = lua_absindex(state, table);
805
806 RefAutolock lock(access);
807
808 if (plugin_is_enabled)
809 {
810 lua_pushlightuserdata(state, this);
811 lua_pushcclosure(state, lua_is_enabled, 1);
812 lua_setfield(state, table, "isEnabled");
813 }
814 if (plugin_enable)
815 {
816 lua_pushlightuserdata(state, this);
817 lua_pushcclosure(state, lua_set_enabled, 1);
818 lua_setfield(state, table, "setEnabled");
819 }
820
821 for (auto it = lua_commands.begin(); it != lua_commands.end(); ++it)
822 {
823 lua_pushlightuserdata(state, it->second);
824 lua_pushcclosure(state, lua_cmd_wrapper, 1);
825 lua_setfield(state, table, it->first.c_str());
826 }
827
828 for (auto it = lua_functions.begin(); it != lua_functions.end(); ++it)
829 {
830 push_function(state, it->second);
831 lua_setfield(state, table, it->first.c_str());
832 }
833
834 if (Lua::IsCoreContext(state))
835 {
836 for (auto it = lua_events.begin(); it != lua_events.end(); ++it)
837 {
838 Lua::Event::Make(state, it->second, it->second);
839
840 push_function(state, &it->second->handler);
841 Lua::Event::SetPrivateCallback(state, -2);
842
843 it->second->active = true;
844 if (it->second->event)
845 it->second->event->bind(DFHack::Core::getInstance().getLuaState(), it->second);
846
847 lua_setfield(state, table, it->first.c_str());
848 }
849 }
850}
851
852void Plugin::push_function(lua_State *state, LuaFunction *fn)
853{

Callers 1

dfhack_open_pluginFunction · 0.80

Calls 8

lua_absindexFunction · 0.85
lua_pushlightuserdataFunction · 0.85
lua_pushcclosureFunction · 0.85
lua_setfieldFunction · 0.85
c_strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected