Merge pull request #46 from ErodeesFleurs/luaFunc

Add parseJson and clientWorld functions to LuaBindings
This commit is contained in:
Kae 2024-03-21 15:38:57 +11:00 committed by GitHub
commit e2fd804f55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 0 deletions

View File

@ -113,6 +113,7 @@ LuaCallbacks LuaBindings::makeUtilityCallbacks() {
callbacks.registerCallback("logWarn", UtilityCallbacks::logWarn);
callbacks.registerCallback("logError", UtilityCallbacks::logError);
callbacks.registerCallback("setLogMap", UtilityCallbacks::setLogMap);
callbacks.registerCallback("parseJson", UtilityCallbacks::parseJson);
callbacks.registerCallback("printJson", UtilityCallbacks::printJson);
callbacks.registerCallback("print", UtilityCallbacks::print);
callbacks.registerCallback("interpolateSinEase", UtilityCallbacks::interpolateSinEase);
@ -192,6 +193,10 @@ void LuaBindings::UtilityCallbacks::setLogMap(String const& key, String const& v
LogMap::set(key, formatLua(value, args));
}
Json LuaBindings::UtilityCallbacks::parseJson(String const& str) {
return Json::parse(str);
}
String LuaBindings::UtilityCallbacks::printJson(Json const& arg, Maybe<int> pretty) {
return arg.repr(pretty.value());
}

View File

@ -16,6 +16,7 @@ namespace LuaBindings {
void logWarn(String const& str, LuaVariadic<LuaValue> const& args);
void logError(String const& str, LuaVariadic<LuaValue> const& args);
void setLogMap(String const& key, String const& value, LuaVariadic<LuaValue> const& args);
Json parseJson(String const& str);
String printJson(Json const& arg, Maybe<int> pretty);
String print(LuaValue const& arg);
LuaValue interpolateSinEase(LuaEngine& engine, double offset, LuaValue const& value1, LuaValue const& value2);

View File

@ -22,6 +22,7 @@ LuaCallbacks LuaBindings::makeUniverseServerCallbacks(UniverseServer* universe)
callbacks.registerCallbackWithSignature<StringList>("activeWorlds", bind(UniverseServerCallbacks::activeWorlds, universe));
callbacks.registerCallbackWithSignature<RpcThreadPromise<Json>, String, String, LuaVariadic<Json>>("sendWorldMessage", bind(UniverseServerCallbacks::sendWorldMessage, universe, _1, _2, _3));
callbacks.registerCallbackWithSignature<void, ConnectionId, String, Json>("sendPacket", bind(UniverseServerCallbacks::sendPacket, universe, _1, _2, _3));
callbacks.registerCallbackWithSignature<String, ConnectionId>("clientWorld", bind(UniverseServerCallbacks::clientWorld, universe, _1));
return callbacks;
}
@ -133,4 +134,8 @@ void LuaBindings::UniverseServerCallbacks::sendPacket(UniverseServer* universe,
universe->sendPacket(clientId, packet);
}
String LuaBindings::UniverseServerCallbacks::clientWorld(UniverseServer* universe, ConnectionId clientId) {
return printWorldId(universe->clientWorld(clientId));
}
}

View File

@ -26,6 +26,7 @@ namespace LuaBindings {
StringList activeWorlds(UniverseServer* universe);
RpcThreadPromise<Json> sendWorldMessage(UniverseServer* universe, String const& worldId, String const& message, LuaVariadic<Json> args);
void sendPacket(UniverseServer* universe, ConnectionId clientId, String const& packetTypeName, Json const& args);
String clientWorld(UniverseServer* universe, ConnectionId clientId);
}
}
}