Page 1 of 1

lua scriping, working with booleans

Posted: Fri Sep 23, 2005 10:19 am
by Berry
I'm using zeus 3.80
You are running quite an old version of Zeus.
I found a weird result in lua scripting. I wrote the following script as example:
I modified your macro to add some extra debug code as shown below:

Code: Select all

function key_macro()
    debug_enable()
    local int t = 8
    local int b = 0
    local string m = ""
    b = (t < 12)
    debug_output("( t = " .. t .. " )\n")
    if (b) then
       debug_output("(t < 12) = True\n")
    end -- if
    m = "True = "..tostring(b)
    b = (t > 12)
    if (b) then
       debug_output("(t > 12) = True\n")
    end -- if
    m = m..", False = "..tostring(b).."\n"
    debug_output(m)
end

key_macro() -- run the macro
When t is 18 I get this output:
About to execute 'd:\temp\test1.lua' macro file
Debug: Initialising macro interface
Debug: debug_enable
Debug: Debug: Macro trace debugging is active.
Debug: debug_output
( t = 18 )
Debug: debug_output
(t > 12) = True
Debug: debug_output
True = false, False = true
Macro produced '10' Warning(s), Error(s) and/or Debug(s) messages.
When t is 8 I get this output:
About to execute 'd:\temp\test1.lua' macro file
Debug: Initialising macro interface
Debug: debug_enable
Debug: Debug: Macro trace debugging is active.
Debug: debug_output
( t = 8 )
Debug: debug_output
(t < 12) = True
Debug: debug_output
True = true, False = false
Macro produced '10' Warning(s), Error(s) and/or Debug(s) messages.
So for me the macro seems to be working fine :?

I am not sure why it is not working for you, but I suspect it might have something todo with the version of Lua you are running. The Lua in Zeus 3.95 is version the latest version 5.0, while I think the version in used in Zeus 3.80 is only something like version 4.0.

Cheers Jussi

Posted: Tue Oct 11, 2005 3:10 pm
by Berry Jansen
Thanks Jussi, for your response.

However, I've found out that if I use:
if (b == 1) then
instead of
if (b) then
it seems to be working in zeus 3.80

Regards,
Berry

Posted: Wed Oct 12, 2005 12:05 am
by jussij
I think this is Lua working as designed :wink:

I am definitely no Lua expert, but I think this is what is going on. This code:

Code: Select all

if (b) then

in Lua terms this means something like if b the object, while this code:

Code: Select all

if (b == 1) then

means if b the object is equal to one.

Since Lua objects are created on demand the if b the object will always true.

Jussi

Posted: Wed Oct 12, 2005 11:22 am
by Berry Jansen
I think this is correct in most of the cases.
However, if I use the following code the object b can be used like it works in the C-language:

Code: Select all

local int b = 0
if (b) then
  print "b = false\n"
else
  print "b = true\n"
end
b=1
if (b) then
  print "b = false\n"
else
  print "b = true\n"
end
b=2
if (b) then
  print "b = false\n"
else
  print "b = true\n"
end
This will insert:
b = false
b = true
b = true

into the document

So b is true when it is not equal to 0. When b is an object it will defenetly be non zero, and therefore always be true.
Using things like
b=(n > 10)
will fill b with 1 when n greater than 10 but with a function (??? I think this is a bug in lua 4.0) when b is less or equal to 10. So b will never be 0, but 1 when true and not 1 when false.

Anyway, from now on I'll use the expression if (b == 1) or if (b ~= 1) when I fill b with a boolean result in my macros.

Berry.