Page 1 of 2
Evaluate string?
Posted: Thu Apr 16, 2015 4:57 pm
by trenatos
I haven't been able to find an answer to this, so I figured I'd check here.
Is it possible to evaluate a string?
Let's say a string contains "put 1 into bla", I'd like to evaluate the string as if it was written in a regular script.
The longer story is that I'd like to be able to let users write scripts that can be read and run at runtime, using LiveCode, rather than having to write an interpreter in LiveCode to... LiveCode.
Re: Evaluate string?
Posted: Thu Apr 16, 2015 5:03 pm
by Klaus
Hi Marcus,
you are looking for DO:
...
put "put 1 into bla" into tCommand
do tCommand
put bla
## -> gives 1
...
Best
Klaus
P.S.
TRY is your friend when dealing with USER INPUT this way!

Re: Evaluate string?
Posted: Thu Apr 16, 2015 5:39 pm
by trenatos
Thanks Klaus, I'll give that a go
I don't know how many beers I owe you at this point, but it's a few!
Re: Evaluate string?
Posted: Thu Apr 16, 2015 8:54 pm
by FourthWorld
If you want them to script in LiveCode why not just give them LiveCode?
Re: Evaluate string?
Posted: Thu Apr 16, 2015 10:15 pm
by dunbarx
Hi.
Know that when including parameters with function or command calls, each is fully evaluated before being passed:
Code: Select all
on mouseUp
doubleTheArgs 5 + 6,sum(5,6)
end mouseUp
on doubleTheArgs var1,var2
answer var1 * 2 && var2 * 2
end doubleTheArgs
You get a pair of "22"s
Craig Newman
Re: Evaluate string?
Posted: Fri Apr 17, 2015 3:23 am
by trenatos
Richard, it's to let others code in LiveCode in order to write small scripts which can be loaded and runtime.
I'm working on a modular testing-engine, it's nice to be able to write small scripts and just drop them into a folder and have them automatically picked up and run, instead of telling other coders to download the software, write new tests, compile for all the platforms, distribute the new binary with the new tests, and make sure everyone has the right version.
Or, just share a set of test files.
The engine is right now written in CFML and does exactly this, tests are written as components and just dropped into a folder containing all tests, the target directories are traversed and each file read, then passed on to each test which returns a bunch of data.
Writing new tests just means writing new components and dropping them in.
I want to do the same but in LiveCode, so a big thing is to be able to just write tests and have them automatically picked up.
Re: Evaluate string?
Posted: Fri Apr 17, 2015 5:21 am
by FourthWorld
trenatos wrote:I'm working on a modular testing-engine, it's nice to be able to write small scripts and just drop them into a folder and have them automatically picked up and run, instead of telling other coders to download the software, write new tests, compile for all the platforms, distribute the new binary with the new tests, and make sure everyone has the right version.
Super cool. Is that for the LiveCode community or something else?
Re: Evaluate string?
Posted: Fri Apr 17, 2015 1:31 pm
by trenatos
Originally it was just for CFML, but I'm thinking of making it a generic test-engine (Thus LiveCode) so you can run it standalone on any platform, using any set of tests you want.
It's a side-project for now, but it's getting a good chunk of my attention, so should have a demo working in the near future.
Re: Evaluate string?
Posted: Fri Apr 17, 2015 4:26 pm
by jacque
The easiest way would be to let the engine do it. Read in the text file, set the script of a button to it, and then send a mouseUp to the button.
Re: Evaluate string?
Posted: Fri Apr 17, 2015 6:47 pm
by trenatos
This really isn't rocket surgery, I just didn't know how to evaluate strings as code (do).
How about threading? Any chance of threading being available? (That's also something I haven't been able to find information about.
Re: Evaluate string?
Posted: Fri Apr 17, 2015 8:42 pm
by FourthWorld
Some network I/O and animation options are non-blocking, but there is no explicit thread management provided in LiveCode at this time.
Re: Evaluate string?
Posted: Fri Apr 17, 2015 11:53 pm
by trenatos
That's too bad.
Threading could speed things up so nicely (My CFML implementation gained some serious speed when I threaded it)
It's going to be fun comparing the two, how fast can I make the LC implementation go?

Re: Evaluate string?
Posted: Sat Apr 18, 2015 1:24 am
by FourthWorld
CFML - this is for Server?
Re: Evaluate string?
Posted: Sat Apr 18, 2015 1:51 am
by trenatos
Originally I wrote it for testing only CFML code, but with a couple of tweaks I could test any code, so I had the idea of moving from a CFML-based implementation, which requires you to run an OpenBD CFML server, to a multi-platform GUI application with no special pre-requisites.
Ironically I won't be able to run tests against LiveCode code due to their silly choice of going with binary source code rather than clear text, but that's a non-issue.
Re: Evaluate string?
Posted: Sat Apr 18, 2015 1:55 am
by FourthWorld
Server scripts can be plain text files.