Lua GetJson on boolean value

62 views
Skip to first unread message

Marc Delpont

unread,
May 16, 2016, 4:51:20 AM5/16/16
to Orthanc Users
Hi,

trying to export Orthanc configuration to remote server with LUA :

function Initialize()
    local conf = GetOrthancConfiguration()
   
SetHttpCredentials('username', 'password')
   
local result = HttpPost('/my/server/uri', DumpJson(conf))
   
PrintRecursive(result)
end

orthanc log shows following line for each boolean value in orthanc config, and config is received by server with null value for all boolean values (true or false) :

LuaContext.cpp:502] Unsupported Lua type when returning Json

In orthanc config files, boolean values are well formatted. For example :

"HttpServerEnabled" : true,

In fact, in LuaContext.cpp boolean values are treated as boolean only if keepStrings parameter is false, but orthanc documentation says :

Setting the optional argument keepStrings to true prevents the automatic conversion of strings to integers.

Boolean are neither strings nor integers, so why are they concerned by this ? BTW it seems that lua_isstring function don't work with integers, so they should always be treated as integers, no ?

Marc


Marc Delpont

unread,
May 16, 2016, 4:54:46 AM5/16/16
to Orthanc Users
Erratum :

In the LUA code there is a second param to true (for keepStrings) to DumpJson :

function Initialize()
    local conf = GetOrthancConfiguration()
   
SetHttpCredentials('username', 'password')

   
local result = HttpPost('/my/server/uri', DumpJson(conf, true))
   
PrintRecursive(result)
end

Marc

Sébastien Jodogne

unread,
Dec 13, 2016, 5:51:32 AM12/13/16
to Orthanc Users
Dear Marc,

Sorry for the delay and thanks for reporting the problem!

Your issue is now fixed in the mainline:

For future reference, you will find 2 files attached to this message in order to reproduce the issue:
  • "node-echo.js" is a simple Node.js server that simply echos the body of incoming HTTP POST requests.
  • "booleans.lua" is Marc's script, modified so that it uses the "node-echo.js" server.
Regards,
Sébastien-
node-echo.js
booleans.lua
Reply all
Reply to author
Forward
0 new messages