Page 1 of 1

Lua reentrant global functions

Posted: Sunday 06 February 2022 18:34
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 ?