Game Development Community

Improving TorqueScript

by James Urquhart · in Torque 3D Professional · 11/05/2012 (11:52 am) · 50 replies

Hey everyone. A while ago as a side-project I decided to have a go at improving TorqueScript ( see http://www.garagegames.com/community/forums/viewthread/131792 ).

The previous "Torquescript has suboptimal performance" thread seems to have pretty much died down, so I figured it best to start from a fresher slate. I'm also interested in everyones perspective on this issue: How can TorqueScript be improved?

At the moment I'm not looking to completely replace the scripting engine, rather I'm focussing more on improving it. e.g. reducing its overuse of strings, adding useful features.

In my fork, besides fixing the "all function parameters are strings" issue (which I made a pull request for), I've revamped the type system so native value types can be used to represent the complex types as opposed to just strings (much like how complex types might be represented in something like Lua). I've also added support for value-based arrays so "object.field = {1,2,3};" and "%value = {1,2,3};" now actually works, though they don't work in expressions since it introduces too much ambiguity in the parser syntax which is a PITA to resolve.

Does anyone have any interest in these changes?
Page «Previous 1 2 3 Last »
#1
11/05/2012 (11:57 am)
Quote:Does anyone have any interest in these changes?
Yes. :)
#2
11/05/2012 (12:02 pm)
Certainly do.
#3
11/05/2012 (12:33 pm)
Hit it with a bigger hammer!
#4
11/05/2012 (12:57 pm)
Just replace it with something better :P

But your changes is a good starting point. Keep it up
#5
11/05/2012 (2:11 pm)
I am very interested in these changes, unfortunately I wont be of much help to you! But I do support your efforts! :)
#6
11/05/2012 (8:01 pm)
Keep up the great work! TorqueScript has been and will likely be a part of this engine for it's time, so why not keep making it better!
#7
11/06/2012 (12:57 am)
If possible( I haven't spent much time in the guts code of TS, I just work with it a lot on the front end), but we should probably make vector manipulation native, instead of having to pass through Vector*() functions.

When programming and you have 2 vectors, you would think of just doing %c = %a - %b, instead of needing to crack out a extra function to do the same with VectorSub, or add, or whatever.

Also, I dunno how anyone else feels about it, but I feel equating "" to 0 would simplify some codestuffs, especially since TS variables are initialized to "" instead of 0. So if you do a check on a variable anticipating nothing, but don't check against a null string, it'll equate to true. So %a == %b, if a is "" and b is 0, they don't equate, which has caused some problems that i had to fix by going back in and creating a second check in the if statements for if %a $= "". It just kinda bulks the code sometimes.

On that note, is there any explicit reason for using $= for string comparisons?
Why not just let it discern which type of == to use based on the variables' content in question?
#8
11/06/2012 (1:36 am)
Thanks for the interest guys. There are still a few issues I need to resolve, but I'll probably push my changes to my T3D fork within the next week or two so you can check them out.

@jeff,

Originally I was thinking of having operator overloading for types, but after some research I concluded it would have required too many substantial changes to the interpreter.

Having a separate string comparison operator ($=) is necessary due to the way comparisons are performed. Normally if you do "==" it will push the numeric value of whatever you are comparing onto a float stack and compare it. If you do "$=" it will push strings to a string stack and do a string comparison on the string value. There isn't any facility to do more generic comparisons of variables as you might find in other scripting languages.




#9
11/06/2012 (2:28 am)
Yeah, that makes sense. I'd figured there was probably some reason or limitation for why it's set up that way, but as said, I hadn't delved into the TS guts so I wasn't positive.
If you say it's a lot of work, I'll go with your knowledge on it.

I wonder if it'd make more sense for an incorrect ==/$= conversion to return as false, instead of true though. Dunno if it's possible to force it to return false instead of true as a default for the wrong comparison, but it's sounding like that may not be easy either.

#10
11/06/2012 (7:02 am)
I just live by the if it's numeric, use == logic... Easy and simple :D
#11
11/06/2012 (1:20 pm)
Quote:object.field = {1,2,3};
Any chance the syntax could be revised to use square brackets? That's pretty much a standard for array literals these days. I really like the feature, though! One of my favourite features from languages like Python, though, is being able to slice arrays:
> a = [1, 2, 3, 4, 5]
> print a[1:3]
[2, 3]
And from several languages, but Haskell comes first to my mind, the ability to construct ranges:
> print [1 .. 5]
[1,2,3,4,5]

On the other hand, since TS is not a general programming language, I don't know how useful these features would be. Especially when you consider the opportunity cost of expending time and effort on them instead of other things.

Huge vote for Jeff Raab's suggestion of native vector maths.

Quote:Having a separate string comparison operator ($=) is necessary due to the way comparisons are performed.
I guess Jeff's question is... can we change that? I definitely think the $= operator is a bit unfriendly. Maybe it's not so bad - after all, Javascript has two different equality operators as well (== and ===), and Lisp has nothing short of five.

One other thing I'd really appreciate is not having to use % for local variables. $ for global variables I can just about stand. But having % symbols everywhere just makes the code really ugly to read. Hopefully this would be a backwards-compatible change - a permissive enough variable naming scheme would allow % in the first character, but not require it.
#12
11/06/2012 (2:22 pm)
I'd be more interested in speed than aesthetics ...
#13
11/06/2012 (6:15 pm)
Speed then aesthetics
#14
11/06/2012 (6:31 pm)
jamesu,
I still need to integrate my changes with yours to see if it will improve speed. I have been out of the loop for a bit so I haven't really looked at it. This winter I will have more time. If you need me to look at anything shoot a note to me.
#15
11/07/2012 (2:40 am)
@daniel,

In this case I just decided to extend the "obj.field = {1,2,3};" syntax which wasn't implemented correctly, so the {} just stuck. [] could certainly be used too.

Ranges and slices would be nice, i'll look into it but as my time is limited I cannot promise anything ;)

Removing the % $ prefixes for variables is possible, though slightly tricky. Currently TS treats words without prefixes as constant strings, e.g "echo(word);" prints "word", "echo(fudge SPC copter);" prints "fudge copter". "new (Script @ Object)(Foo){};" makes a new ScriptObject. I don't know if anyone actually uses TS like this, but stranger things have happened ;)

@steve @jimmy,

My primary interest is improving the speed, though I'm still open to adding new things provided they don't end up being a PITA to implement. Since I'm knee deep in the interpreter code now is a better time than any to suggest such things. :)

@frank,

Any assistance is appreciated.

#16
11/07/2012 (2:58 am)
Quote:
Since I'm knee deep in the interpreter code now is a better time than any to suggest such things

Can I throw @= into the mix then? There's +=, -= etc but no @= ...and torsion doesn't complain about it so it always catches me out.


EDIT: fixed quote tags
#17
11/07/2012 (3:55 am)
Sorry, what's that operator used for?

The other issue with dropping % and $ prefixes is object names. Defining something like 'itemdata(cat)' means 'cat' is always going to refer to the datablock. It's a lot easier to accidentally re-declare 'cat' in your code as a variable if you drop the prefixes, which would lead to all kinds of issues.
While it might be 'ugly' to have the prefixes, they're very useful at at-a-glance breakdown of what the variable is and does and helps prevent object name issues like that.
#18
11/07/2012 (12:28 pm)
Fair enough on both counts. All right, I retract my request. Creating string literals without "quotes" has always terrified me, though.

Jeff, I think Josh's suggestion would look something like this:
> %myString = "Hello, ";
> %myString @= "World";
> echo(%myString);
Hello, World
#19
11/07/2012 (12:45 pm)
In all fairness, I never use it that way. I can see why it'd do that, but honestly, I don't ever use string literals like that. If I'm using a string, I use the quotations.

As for Josh's suggestion, that actually makes a lot of sense. Cleaner than %mystring = %mystring SPC "World"; anyways.
#20
11/07/2012 (3:12 pm)
What language is @= from? That functionality would fall under += in my book, as would string1 + string2; intuitive concatination....
Page «Previous 1 2 3 Last »