From 6aeed92139a36208fd2197a799efa303707b8ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Tue, 10 Jan 2023 10:36:23 +0100 Subject: [PATCH] Use native Defold json encode and decode functions (#65) * Added missing engine API function * Replace Lua json with native Defold json * Update example.script * Update CHANGELOG.md Co-authored-by: Tom Glenn <289945+tomglenn@users.noreply.github.com> --- CHANGELOG.md | 3 +++ README.md | 2 ++ example/example.script | 2 +- nakama/engine/defold.lua | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5c3243..28a4c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Use native Defold json encode and decode functions + ### Added - Added optional native b64 encode and decode using extension-crypt if it exists diff --git a/README.md b/README.md index 73df9c3..2e9411d 100644 --- a/README.md +++ b/README.md @@ -326,6 +326,8 @@ The engine module must provide the following functions: * `message` - Message to send * `callback` - Function to call with message returned as a response (message) +* `uuid()` - Create a UUID + ## API codegen diff --git a/example/example.script b/example/example.script index d7e707f..a71f6fa 100644 --- a/example/example.script +++ b/example/example.script @@ -49,7 +49,7 @@ local function login(client) local success = true - if session and nakama_session.is_token_expired_soon(session) and not nakama.is_refresh_token_expired(session) then + if session and nakama_session.is_token_expired_soon(session) and not nakama_session.is_refresh_token_expired(session) then log("Session has expired or is about to expire. Refreshing.") success = refresh_session(client, session) elseif not session or nakama_session.is_refresh_token_expired(session) then diff --git a/nakama/engine/defold.lua b/nakama/engine/defold.lua index f031369..4b74bdc 100644 --- a/nakama/engine/defold.lua +++ b/nakama/engine/defold.lua @@ -22,6 +22,12 @@ local uri_decode = uri.decode uuid.seed() +-- replace Lua based json.encode and decode with native Defold functions +-- native json.encode function was added in Defold 1.3.7 +-- native json.decode function has been included in Defold "forever" +json.encode = _G.json and _G.json.encode or json.encode +json.decode = _G.json and _G.json.decode or json.decode + local M = {} --- Get the device's mac address.