| 800 | } |
| 801 | |
| 802 | void 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 | |
| 852 | void Plugin::push_function(lua_State *state, LuaFunction *fn) |
| 853 | { |
no test coverage detected