lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2012/5/29 Paul K <paulclinger@yahoo.com>:

>
> A simple test using serialize.lua from metalua:
>
> require "serialize"
> local s = serialize {[math.huge] = -math.huge}
> local _, err = loadstring(s)
> print(s, err)
>
> This outputs:
>
> return { [1.#INF] = -1.#INF }   [string "return { [1.#INF] = -1.#INF
> }"]:1: ']' expected near '#'
>
> Does this indeed need to be handled as a special case, or am I missing
> some simple solution?
>

Yes. You need to create a global variable called "inf".
Then standard Lua (5.1 and 5.2) can do it.
----
loadstring = loadstring or load
inf = math.huge

function testinf()
   local s=tostring(math.huge)
   local f= loadstring("return "..s)
   return f()
end

print(1/testinf()) --> true
print( testinf()==inf) -->true
----