Lua reentrant global functions

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
mgugu
Posts: 226
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Lua reentrant global functions

Post by mgugu »

Hi,
I often put common funtions in helpers section of the global_data script, this works fine but when I want write a reentrant function I get an error when trying to reference the function inside the script itself.
Example this function to pretty print any lua table:

Code: Select all

dumpTable = function (o)
   if type(o) == 'table' then
	  local s = '{ '
	  for k,v in pairs(o) do
		 if type(k) ~= 'number' then k = '"'..k..'"' end
		 s = s .. '['..k..'] = ' .. dumpTable(v) .. ','
	  end
	  return s .. '} '
   else
	  return tostring(o)
   end
end
The dumpTable call inside the function itself raises an error due to a reference problem.
Any body knows how to write the reference properly ?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest