Not signed in (Sign In)
  1.  
    Im wondering, and really hopeing that there is a way, to evaluate a logical equation that is stored in a string.


    Here is what I am trying to do..


    inputString = "((1==2) or ((\"Cat\" == \"Cat\") and 2234 ==1))"
    if inputString then
       do stuff
    end



    I want to be able to change the value of inputString while the program is running.

    or prehaps


    if evaluateString(inputString) then
      do stuff
    end
  2.  
    perhaps this would work?



    inputString = " (1 ==2) or (1!=1)"

    if loadstring("if (" + inputString + ") then return true; else return false; end ") then
      doStuff();
    end




    now, i just wish I could test lua code on my work pc.....
  3.  
    Posted by: xenoputtss on Feb 7 2006, 12:29 PM
    perhaps this would work?



    inputString = " (1 ==2) or (1!=1)"

    if loadstring("if (" + inputString + ") then return true; else return false; end ") then
      doStuff();
    end


    now, i just wish I could test lua code on my work pc.....

    The problem is that loadstring will not be available in WoW's Lua until 1.10. So until then you can use "RunScript()" However, again you need to code in Lua, not Java so it would be something like:

    [pre]
    inputString = "((1==2) or ((\"Cat\" == \"Cat\") and 2234 ==1))"

    RunScript([[
        if(]]..inputString..[[) then
            doStuff();
        end
    ]]);
    [/pre]

    PS: There IS a standalone Lua compiler available for free from www.Lua.org
World of Warcraft™ and Blizzard Entertainment™ are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the U.S. and/or other countries.