Author Topic: eggscript -- torquescript extension (v0.2)  (Read 509 times)


https://github.com/bansheerubber/eggscript

i've been working on making a torquescript tokenizer/lexer/whatever you want to call it and the vanilla torquescript part of it is finished. i was thinking that i could add a bunch of additional features that could polyfill down to normal torquescript. ideas include:

- vector operators, no more nested vectorAdd/vectorSub bullstuff. you might write:
%distance = `||%vector1 - %vector2||`;
%dot = `%vector1 . %vector2`;

not really sure how to do the syntax for operations like cross product, distance, unit vectors, etc. open to any ideas on this one

- arrays are treated as objects. this would be polyfilled down to something efficient, but in eggscript you might write:
%array = [];
for(%i = 0; %i < 50; %i++) {
     %array.append(getRandom(1, 5000));
}
%array.sort();
for(%number in %array) {
     echo(%number);
}


- inlining functions for optimization (no more 2-6 microsecond overhead for calling functions!)
- using a string table to shorten variable names (better performance, especially for large loops)

features already in eggscript include:
- string templates. i.e. %variable = $"Welcome to {%client.getPlayerName()}'s server!"; will polyfill to %variable = "Welcome to " @ %client.getPlayerName() @ "'s server!";
- minification https://bansheerubber.com/i/f/GeuGv.png
- de-minification aka pretty printing

willing to look into additional syntax to add to this, really looking forward to making a bunch of cool extensions
« Last Edit: September 15, 2020, 05:20:00 PM by Gytyyhgfffff »


after some discussion with others on bcc i've come up with this vector syntax proposal:

%addition = `%vector1 + %vector2`;
%subtraction = `%vector1 - %vector2`;
%scale1 = `%vector * %scalar`;
%scale2 = `%vector / %scalar`;
%dot = `%vector1 . %vector2`;
%magnitude = `||%vector||`;
%distance = `||%point - %origin||`; // note: this pattern will specifically be polyfilled down to vectorDist(%point, %origin)
%normalize = `^%vector`; // aka the unit vector, hense the carrot character

any vector operations that you want to do will be surrounded by backticks so that the transpiler can recognize everything inside of them as vectors. i've left out vector crossing because there isn't really a good symbol to use for its operator, and i find myself using vector cross so infrequently that i don't think we would need an operator for it anyways.

an example like
%theta = mRadToDeg(mACos(vectorDot(%this.getForwardVector(), vectorNormalize(vectorSub(%targetPosition, %position)))));
could simplify down to
%theta = mRadToDeg(mACos(`%this.getForwardVector() . ^(%targetPosition - %position)`));
« Last Edit: August 31, 2020, 12:21:03 AM by Gytyyhgfffff »

that's loving dope as hell, working with vectors has always been a pain in ts

makin me want to get back into modding this game

some more highlights from bcc so i don't forget them: supporting generator-like functions

this sounds a lot more amazing than it actually will be. as everyone knows, in torquescript you have stuff like findFirstFile, initContainerRadiusSearch, etc where you have to do some weird while/for loop to iterate through the contents you get back. instead, we were thinking of something along these lines:

for(%col in radius(%radius, %masks)) {
    ...
}

for(%fileName in file(%path)) {
    ...
}

for(%element in tokenize(%string, " ")) { // would be polyfilled to getWord/getTab/etc based on the token provided. otherwise, use nextToken
    ...
}


this for/in structure would be an addition to what i was already planning on doing, which is iterating through scriptgroups/simsets/arrays using the same syntax

not sure how much time i'll have to work on the project this week, so progress might be a little slow for a while. but i'm expecting it to pick back up once i get my first round of college homework out of the way.

one of my plans to counter the whole not being able to work on it thing is to clean up the code so people can start contributing themselves if they really want to, i think it would be really neat to build this language as a community and as stated in the op i am really looking forward to explore more syntax ideas. nothing is a bad idea here, since we can only go up from torquescript lol
« Last Edit: August 31, 2020, 02:08:23 PM by Gytyyhgfffff »

does the converter have the flexibility to convert any tokens or syntax into torquescript if you want or is it hard coded because ive wanted to make a visual scripting tool for blockland and it seems like a good library
« Last Edit: August 31, 2020, 04:24:25 PM by PhantOS »

most of the token definitions are in regex.py, i have no clue what you could do with this if you modify it. probably interpret any other scripting language, provided you write the correct expression classes n such


demo of vector operation parser i just made:

thinking of having {...} escape out the operators for number calculations while in vector mode. for instance, if you need to calculate the velocity for something and want to do it all inline since its easier: %velocity = `%aimVector * {%muzzleVelocity - %speedModifier}`;
« Last Edit: August 31, 2020, 09:01:57 PM by Gytyyhgfffff »

« Last Edit: September 15, 2020, 05:22:32 PM by Gytyyhgfffff »

- minification https://bansheerubber.com/i/f/GeuGv.png
excuse me for being naive but whats the point of doing this? i know so many people who did this with their code and it made it so annoying trying to find stuff to reference from it.

excuse me for being naive but whats the point of doing this? i know so many people who did this with their code and it made it so annoying trying to find stuff to reference from it.
minification is a concept that requires your parser to have basically a complete knowledge of what is going on in the code. the minification aspect was more sort of a proof of concept and also proof to show that what i had was the real deal. additionally, eggscript can read minified code and export it back out to a readable format. this was an important test for the parser, since it showed that you could throw actual junk code at it and it'll still handle it perfectly. if you know about any mods that use minified code, you can take their script files and plug them into https://bansheerubber.com/eggscript to get back a readable version (like gcat's weapons). honestly, i don't expect anyone to use the minification for the reason you mentioned. places like blockland glass certainly wouldn't accept that sort of code
« Last Edit: September 19, 2020, 08:57:40 PM by Gytyyhgfffff »

excuse me for being naive but whats the point of doing this? i know so many people who did this with their code and it made it so annoying trying to find stuff to reference from it.
generally to make javascript files smaller for sending over the internet by removing any unnecessary whitespace and shortening variable names. it is also used to obfuscate, meaning literally causing the problem that you just described, but if you ask me deliberately obfuscating code that you're giving someone else to run on their machine is a dweeb attribute. outside of javascript (and css I guess) for a website it serves no purpose aside from obfuscation so if anyone uses it in any other context you can rest assured they're a dweeb