From e1645f37fc72e7733b64c51ffbee0370e13cbe29 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 19 Jul 2023 01:16:22 +1000 Subject: Support for player entity message commands --- source/core/StarLua.cpp | 11 +++++++++++ source/core/StarLua.hpp | 3 +++ 2 files changed, 14 insertions(+) (limited to 'source/core') diff --git a/source/core/StarLua.cpp b/source/core/StarLua.cpp index 4e89097..287bf5c 100644 --- a/source/core/StarLua.cpp +++ b/source/core/StarLua.cpp @@ -1095,6 +1095,17 @@ LuaFunction LuaEngine::createRawFunction(lua_CFunction function) { return LuaFunction(LuaDetail::LuaHandle(RefPtr(this), popHandle(m_state))); } +LuaFunction LuaEngine::createFunctionFromSource(int handleIndex, char const* contents, size_t size, char const* name) { + lua_checkstack(m_state, 2); + + handleError(m_state, luaL_loadbuffer(m_state, contents, size, name)); + + pushHandle(m_state, handleIndex); + lua_setupvalue(m_state, -2, 1); + + return LuaFunction(LuaDetail::LuaHandle(RefPtr(this), popHandle(m_state))); +} + void LuaEngine::pushLuaValue(lua_State* state, LuaValue const& luaValue) { lua_checkstack(state, 1); diff --git a/source/core/StarLua.hpp b/source/core/StarLua.hpp index 500923d..dda0802 100644 --- a/source/core/StarLua.hpp +++ b/source/core/StarLua.hpp @@ -310,6 +310,7 @@ public: using LuaTable::contains; using LuaTable::remove; using LuaTable::engine; + using LuaTable::handleIndex; // Splits the path by '.' character, so can get / set values in tables inside // other tables. If any table in the path is not a table but is accessed as @@ -530,6 +531,8 @@ public: LuaFunction createRawFunction(lua_CFunction func); + LuaFunction createFunctionFromSource(int handleIndex, char const* contents, size_t size, char const* name); + LuaThread createThread(); template -- cgit v1.2.3