PDA

View Full Version : Is there an eval() command?



thisisauniqueusername
10-28-2008, 04:12 PM
Is there a way to execute code that is stored in a string in AMS?

Currently I can write the string to a file and then run the file like:


myScript="Debug.ShowWindow(true);Debug.Print('Hello World');"
myLocation="C:\\MyFile.lua"
TextFile.WriteFromString(myLocation, myScript, false);
Application.RunScriptFile(myLocation);

or I can assign it to a hotspot and then execute the on click event like:


myOtherScript="Debug.ShowWindow(true);Debug.Print('Goodbye World');"
Page.SetObjectScript("MyHotspot", "On Click", myOtherScript);
Page.ClickObject("MyHotspot");

Is it possible to just do some type of eval(myScript)?

This would be used with pulling scripts from a MYSQL/SQLLITE DB and then executing them. They would all be valid Lua Scripts.

TJ_Tigger
10-28-2008, 04:25 PM
There is dofile() and require().

Here is the online help file
http://www.indigorose.com/webhelp/ams/Scripting_Guide/Other_Built-in_Functions.htm#_Toc47928356

ShadowUK
10-28-2008, 04:49 PM
There is dofile() and require().

Here is the online help file
http://www.indigorose.com/webhelp/ams/Scripting_Guide/Other_Built-in_Functions.htm#_Toc47928356

Then again.


local sCode = "Dialog.Message(\"HAI THAR\", \"What's up people.\");";

loadstring(sCode)()

eval = loadstring, You need the () at the end as well, If you want to catch the error do this.


local sCode = "broken_code()";

local function RunString(sString) return loadstring(sString)(); end

ret, err = pcall(RunString, sCode);

if (err) then
Dialog.Message("OH SHI-", "An error occured, Blah blah blah.\r\n\r\n\t"..err.."\r\n\r\nWe recommend you do nothing and moan about it.");
end

thisisauniqueusername
10-28-2008, 05:02 PM
Then again.


local sCode = "Dialog.Message(\"HAI THAR\", \"What's up people.\");";

loadstring(sCode)()

eval = loadstring, You need the () at the end as well, If you want to catch the error do this.


local sCode = "broken_code()";

local function RunString(sString) return loadstring(sString)(); end

ret, err = pcall(RunString, sCode);

if (err) then
Dialog.Message("OH SHI-", "An error occured, Blah blah blah.\r\n\r\n\t"..err.."\r\n\r\nWe recommend you do nothing and moan about it.");
end

Thank you - exactly what i was looking for :)