lua-users home
lua-l archive

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


Hi,

I have this code snippet:


function compile(spec)
	local funcBody = string.format('return function() return %s end', spec)
	return loadstring(funcBody)
end

f = compile('2==3')
print(f())

This prints 0 on Lua 4.0 and function: 0x804eb60 on Lua 5.0
To print false (a.k.a 0) in Lua 5.0 I had to wrote
print(f()())

Why I this? Did I write compile function wrong?

My goal is to create a Lua function from the user-specified string and
evaluate it.

-- 
Regards, max.