Skip to content

Commit

Permalink
Use native Defold json encode and decode functions (#65)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
britzl and tomglenn authored Jan 10, 2023
1 parent c3b7e66 commit 6aeed92
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions nakama/engine/defold.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6aeed92

Please sign in to comment.