Game Development Community

TorqueScript Improvement Status

by JeffH · in Torque 3D Professional · 03/01/2014 (4:47 pm) · 35 replies

Current improvements to TS:

Check it out here:

https://github.com/JeffProgrammer/Torque3D

*Lamda functions (original code credits to Konrad Kiss from his resource)
*Native global variable arrays
*Native local variable arrays
*foreach loop for iterating through native arrays.

Other plans that I have (Difficulty for me indicated):

* pass arrays to functions [harder]
* make object arrays (%obj.array[] = new array[3];) [harder]
* @= operator [mid]
* fix do-while loops to end with a semicolon [easy]

Native arrays do NOT break current arrays in torquescript. In fact, to access elements of the new array, its the same way. You don't even have to have to use the new array declaration if you still wish to use torquescript style arrays. What this is for is eventually be able to just pass the array instead of passing each individual variable. It kinda makes a wrapper for it. If you are still confused, or need more clarification, see post 18.

Code examples:

//Lamda function:
function bleh() {
   schedule(1, 0, function() {

   });
}

// local array
function blah() {
   %array[] = new array[2];
}

// global array
$array[] = new array[5];

// foreach iterator with array
function arrayForTest() {  
   %array[] = new array[3];  
   %array[1] = 1;  
   foreach (%i in %array[]) {  
      echo(%i);  
   }  
}
Page«First 1 2 Next»
#21
03/14/2014 (7:53 pm)
I'm considering adding a small pre processor to torqueScript that will allow you to basically define constants, something ts is lacking. It will be easier to do pre processor instead of making const part of the VM as a pre processor can be done without modifying the bytecode.

I know, I still have to finish the arrays, they will come eventually, taking a small break from them :P
#22
03/14/2014 (9:22 pm)
Cool! This is really great work.
#23
04/05/2014 (3:51 pm)
I'm debating on whether or not to keep modifying TorqueScript, or to integrate a language such as Squirrel or Lua. I just started looking into Squirrel and it looks awesome. Especially how you can extend classes, looks very similar to C++ for a scripting language.

It would be nice to finally script custom classes as it looks like you can do that in Squirrel instead of using the legacy

new SimObject() {
  class = "bleh";
};

Also you could create code that is independent to the scripting system as well, by having custom Squirrel only classes. Would speed stuff up too, especially if you wanted to do some vector math in script only, or other things.

For anybody who has used squirrel, how is performance. I've never really used many scripting languages before.
#24
04/05/2014 (9:09 pm)
A blog post by James Urquhart that may be of interest. He was doing some work on embedding Lua in T2D as well, which is exciting. I would personally prefer Lua, as a traditional class hierarchy isn't that interesting to me. Metatables are really cool though.
#25
04/06/2014 (12:16 pm)
Both squirrel and lua are fairly easy to embed, though keep in mind the way torques object system works (i.e its pretty loose) can better be implemented in lua. Squirrels classes are much more strict and its tables are not nearly as powerful as luas.

@Daniel

If you are interested I might get around to sharing my lua implementation. In the end I made a more generic interface which could be useful for binding other languages too in a loose fashion...

#26
04/06/2014 (1:00 pm)
@James

I have a plan to add Lua to Torque3D, if you can share your implementation would you do me a great favor :D
#27
04/06/2014 (1:05 pm)
@Luis if you ever add it, mind making it optional to have in the engine like how physX or bullet is?
#28
04/06/2014 (1:05 pm)
To be honest, I think that we should just stick to TorqueScript. Lua is an entirely different language.

If it would let it do more things, then it should be optional, but we should at least have TorqueScript.
#29
04/06/2014 (1:08 pm)
@raa the intention is to not replace TS. I'd miss TS too much if I replaced it. (It's the reason why we chose T3D over other engines, because in my team we are all accustomed to using TS :D)

What i really like about lua/squirrel is the fact that there are coroutines and generators that can be used, unlike where it would take me a while to change the bytecode to allow TS to have those features.

I have to be really careful changing too much bytecode, I don't want to cause the scripting engine to have hiccups either. TS was meant to be simple by design and flexible as well.

I am looking at both lua and squirrel and honestly, I prefer the C style syntax that squirrel has. Might go about implementing.

If I ever happen to finish this thing, feel free to use it guys :P

+ you could use lua/squirrel as a mod api and compile all the torquescript.

The possibilities are unlimited c:
#30
04/06/2014 (3:17 pm)
@Luis I'll see tomorrow what state the code is in. Its for Torque2D and it doesn't have the best bindings in the world ATM, but it works. ;)
#31
04/06/2014 (4:18 pm)
Jeff: we're big fans of making everything modular!

raa: "Lua is an entirely different language." That's a good thing! :P Aside from the features of the language itself, switching to (or at the very least, making available) a new language would open up lots of existing libraries, tutorials, and people who know how to use the language!

James and Luis: :D
#32
04/06/2014 (8:36 pm)
@James: i'll add a :D as well. Your code always has a knack for making its way into the main T2D repo. This would be very interesting.
#33
04/14/2014 (6:44 pm)
@Mike @Luis

I pushed my lua interpreter code to https://github.com/jamesu/Torque2D/tree/scripting_refactor

It includes an abstract ScriptEngine interface which has similar functions to the Con namespace for executing functions and scripts. These functions make use of a ScriptStackValueRef object (similar to my console refactor stuff for Torque3D) which allows one to transparently pass in basic types to lua. The interface is generic enough you could probably write a bindings for Squirrel, GameMonkey, etc too.

In terms of replacing TorqueScript, this code alone wont do it. Its more of a concept of how lua can work within the existing binding system. An improved implementation would probably rewrite the ConsoleFunction/ConsoleMethod macros as well as improve the type system.

There is also a bit of a problem with fully replicating the namespace system in lua due to the order in which things happen when adding an object. Its possible this could be worked around by deferring some linking still after onAdd, but its fairly tricky to get behaviour which makes sense in this sort of situation. Also handling re-linking namespaces during the middle of an objects lifespan is more than likely going to be impossible to get right.

In any case, I hope the code is of use to someone interested in embedding lua!
#34
04/14/2014 (6:54 pm)
@JamesU I may use this for squirrel (if I ever get around too it, i wanted too but I have other stuff I'm busy with atm). The intention of squirrel was to be an addon, rather than a replacement :)
#35
04/16/2014 (11:46 am)
@James, thx a lot.

Sure will be a good starting point when I start to implement Lua in T3D.
Page«First 1 2 Next»