BRL.MaxLua

BlitzMax Forums/BlitzMax Programming/BRL.MaxLua

rs22(Posted 2009) [#1]
Hi,

How can I return True or False from a BlitzMax type method to Lua?

Example:
Type MyType
	Method isTrue(a)
		If a = whatever
			Return True
		Else
			Return False
		EndIf
	EndMethod
EndType

I use LuaRegisterObject. My Lua code doesn't seem to recognise the result returned.

Thanks for any help!


N(Posted 2009) [#2]
Can we see your Lua script?

Edit: Anyhow, I'm sure when I see the script you'll be checking for true/false, which are booleans and not numbers. Numbers and booleans in Lua are not exactly the same, so you're not going to be able to test for them. You'll have to test for 1 or 0, or modify the invoker to check for some sort of metadata to specify when it should treat the result of a method as a boolean value.

While I'm at it, consider looking at my LuaRef code in my bmax-misc Github repo. MaxLua is pretty flawed, so I figure what I wrote is a bit closer to a good alternative.


Htbaa(Posted 2009) [#3]
Return an integer. From the Pil:
Lua considers both zero and the empty string as true in conditional tests


So return -1 for false, and anything else for true.


N(Posted 2009) [#4]
So return -1 for false, and anything else for true.
That's not going to work if you're testing the returned number against a boolean. Run 'print(-1==false)' through an interpreter. Different data types are never equal.


JoshK(Posted 2009) [#5]
Nilium's implementation is so much better than MaxLua. Use it!