From ec4787d78e3d329082b4887748b2bf92c290ddec Mon Sep 17 00:00:00 2001 From: ErodeesFleurs <3353309908@qq.com> Date: Fri, 22 Mar 2024 15:46:30 +0800 Subject: [PATCH 1/2] world.id() for server --- source/game/scripting/StarWorldLuaBindings.cpp | 5 +++++ source/game/scripting/StarWorldLuaBindings.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/source/game/scripting/StarWorldLuaBindings.cpp b/source/game/scripting/StarWorldLuaBindings.cpp index 7d74a98..cc91ec2 100644 --- a/source/game/scripting/StarWorldLuaBindings.cpp +++ b/source/game/scripting/StarWorldLuaBindings.cpp @@ -375,6 +375,7 @@ namespace LuaBindings { callbacks.registerCallback("isClient", []() { return false; }); callbacks.registerCallback("isServer", []() { return true; }); + callbacks.registerCallbackWithSignature("id", bind(ServerWorldCallbacks::id, serverWorld)); callbacks.registerCallbackWithSignature("breakObject", bind(ServerWorldCallbacks::breakObject, serverWorld, _1, _2)); callbacks.registerCallbackWithSignature("isVisibleToPlayer", bind(ServerWorldCallbacks::isVisibleToPlayer, serverWorld, _1)); callbacks.registerCallbackWithSignature("loadRegion", bind(ServerWorldCallbacks::loadRegion, serverWorld, _1)); @@ -1086,6 +1087,10 @@ namespace LuaBindings { return world->clientWindow(); } + String ServerWorldCallbacks::id(WorldServer* world) { + return world->worldId(); + } + bool ServerWorldCallbacks::breakObject(WorldServer* world, EntityId arg1, bool arg2) { if (auto entity = world->get(arg1)) { bool smash = arg2; diff --git a/source/game/scripting/StarWorldLuaBindings.hpp b/source/game/scripting/StarWorldLuaBindings.hpp index 965f025..010affd 100644 --- a/source/game/scripting/StarWorldLuaBindings.hpp +++ b/source/game/scripting/StarWorldLuaBindings.hpp @@ -73,6 +73,7 @@ namespace LuaBindings { } namespace ServerWorldCallbacks { + String id(WorldServer* world); bool breakObject(WorldServer* world, EntityId arg1, bool arg2); bool isVisibleToPlayer(WorldServer* world, RectF const& arg1); bool loadRegion(WorldServer* world, RectF const& arg1); From 443e6459b9458820dee087df61c3a3aa1c6bfa5e Mon Sep 17 00:00:00 2001 From: ErodeesFleurs <3353309908@qq.com> Date: Fri, 22 Mar 2024 15:56:20 +0800 Subject: [PATCH 2/2] fix pushGlobalContext error --- source/base/StarAssets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp index 2bbe509..d4b7228 100644 --- a/source/base/StarAssets.cpp +++ b/source/base/StarAssets.cpp @@ -111,7 +111,7 @@ Assets::Assets(Settings settings, StringList assetSources) { auto luaEngine = LuaEngine::create(); m_luaEngine = luaEngine; - auto pushGlobalContext = [&luaEngine](String const& name, LuaCallbacks & callbacks) { + auto pushGlobalContext = [&luaEngine](String const& name, LuaCallbacks && callbacks) { auto table = luaEngine->createTable(); for (auto const& p : callbacks.callbacks()) table.set(p.first, luaEngine->createWrappedFunction(p.second));