Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
logical operators as variables? — Gideros Forum

logical operators as variables?

piepie Member
edited October 2015 in General questions
Hi, do you know if it's possible to set logical operators as variables like in:
 
local a = 2
local b = 5
 
local operator = "<"
 
if a operator b then
	print("working")
end
Thank you :)

Comments

  • unfortunately I think there is no way, you would need to create a function which checks for all possible operators you need and performs needed operation, like
    function operator(op, a, b)
       if op == "==" then
          return a == b
       elseif op == ">" then
          return a > b
       --etc
       end
    end

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • It might be possible with the new Macros extension, but until we have a proper go with it then I don't know for sure.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • hgy29hgy29 Maintainer
    I would have used functions to wrap operators:
    local function operatorLT(a,b) return a<b end
     
    local a = 2
    local b = 5
    local operator=operatorLT
     
    if operator(a,b) then
     print("working")
    end

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.