Evaluate string?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Evaluate string?

Post by trenatos » Thu Apr 16, 2015 4:57 pm

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.
Marcus

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Evaluate string?

Post by Klaus » Thu Apr 16, 2015 5:03 pm

Hi Marcus,

you are looking for DO:
...
put "put 1 into bla" into tCommand
do tCommand
put bla
## -> gives 1
...
:D


Best

Klaus

P.S.
TRY is your friend when dealing with USER INPUT this way! 8)

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: Evaluate string?

Post by trenatos » Thu Apr 16, 2015 5:39 pm

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!
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Evaluate string?

Post by FourthWorld » Thu Apr 16, 2015 8:54 pm

If you want them to script in LiveCode why not just give them LiveCode?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Evaluate string?

Post by dunbarx » Thu Apr 16, 2015 10:15 pm

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

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: Evaluate string?

Post by trenatos » Fri Apr 17, 2015 3:23 am

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.
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Evaluate string?

Post by FourthWorld » Fri Apr 17, 2015 5:21 am

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: Evaluate string?

Post by trenatos » Fri Apr 17, 2015 1:31 pm

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.
Marcus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Evaluate string?

Post by jacque » Fri Apr 17, 2015 4:26 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: Evaluate string?

Post by trenatos » Fri Apr 17, 2015 6:47 pm

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.
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Evaluate string?

Post by FourthWorld » Fri Apr 17, 2015 8:42 pm

Some network I/O and animation options are non-blocking, but there is no explicit thread management provided in LiveCode at this time.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: Evaluate string?

Post by trenatos » Fri Apr 17, 2015 11:53 pm

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? :D
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Evaluate string?

Post by FourthWorld » Sat Apr 18, 2015 1:24 am

CFML - this is for Server?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: Evaluate string?

Post by trenatos » Sat Apr 18, 2015 1:51 am

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.
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Evaluate string?

Post by FourthWorld » Sat Apr 18, 2015 1:55 am

Server scripts can be plain text files.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”