Skrypt: an easy-to-use scripting language to replace Expression 2 in S&box
9 replies, posted
For the past couple months I have been developing my very first scripting language: Skrypt (derived from my alias 'KrypteK'). The main goal of Skrypt is to be something similar to what Expression 2 is in Gmod; an easy-to-use scripting language, which can be used in-game to do various things that might be too tedious or unrealistic to do as a full mod. Skrypt already supports more features than Expression 2 currently does, most notably OOP. Aside from that, I've tried to make it 'feel' similar to Python/JavaScipt, in that the language isn't too strict in how you use it (variables are mutable by default, and functions are just like any other object in Skrypt).
If you're interested, here's the link to the GitHub page: GitHub
I'd love to hear your feedback and suggestions.
You absolute winner, I've seen how much time and effort you've been putting into this and I'm sure you'll be able to make something great out of this. Keep it up Ø✓
One of the biggest things I want to see in this project is massive flexibility like Gmod has. Gmods huge growth is all thanks to how you can quite literally make your own games within it without even going through the engine itself. It probably made it one of the most flexible games out there tbh.
So I thought about leaving an update here after about 2 months. Most of the time since then I haven't really worked on Skrypt much, until recently. I have been working on cleanup up existing code, fixing small bugs, and I'm overcoming some laziness by actually adding comments (yay so now everyone will know how I made it I hope!). As of this post, most the commenting work has been done in all files related to parsing (Click here if you're curious).
All in all, the code should be more robust and easier to read! Next steps would be to design something to run multiple files. Right now I'm thinking of a project file containing links to all Skrypt files part of that project, although I am also thinking of doing all of this within the Skrypt files themselves. This means that you only run one file, and in that file you might have a statement like:
import "someOtherFile.skt"
This would then run everything from that file, wherever it gets called. I'm curious to know what any of you think of this, or if you have any other ideas!
Can confirmed with a "totally non-biased" opinion that this is far better than Expression2 already.
Would be better if I could think of more libraries to write in :P
MULTIPLE FILES
I added support for multiple file execution by means of an 'include' statement:
https://i.imgur.com/te3CxJh.png
During the parsing stage, the compiler looks for include statements. Once it finds one, it expects it to be followed by a string. That string represents a path
relative to the 'root' file, with an optional file extension (the compiler will automatically add it). The compiler then opens that file, parses it, and puts the
resulting node wherever the parser currently is at that point (in the case of the code in the picture, the include statement is at the top, so generated node will
come first).
You can see this as copying and pasting the code from the included file into the file that's being parsed, at the location of the include statement.
IMPROVED CALL STACKS
With this new feature, I also had to work some more on call stacks, and the way they get displayed during an exception. The result now looks like this:
https://i.imgur.com/k6N1J1E.png
It displays the error message, then the file and location of that error, then the call stacks leading up to it. It also makes sure not to repeat call stacks with the
same information (for example with recursive functions). Later on I'll have to improve the column/row counters so they count tabs as 4 columns, so it makes
more sense for the average joe.
OTHER SMALL FIXES
Previously, the 'self' variable would only be created once you directly call a function from an object (e.g Object.Function()). So when you'd use the using
statement on that object, and then call the variable created from that function, the 'self' variable inside of it wouldn't exist. Now functions will remember
the class that they were in when they were created, so now the 'self' variable would still get properly created.
Cases in which a keyword would be the start of an identifier (e.g trueVariable) would previously be parsed as a 'true' (boolean) token and a 'Variable'
(identifier) token. Now these cases will always be handled as identifiers.
I've been out of the garrysmod scene for awhile now but this looks very nice.
+1
Great work on this, and I think its really cool regardless, but why would someone use this over the C# scripting layer they've already added?
This is not entirely meant to replace C# to make addons, gamemodes etc, but more meant to enable users to quickly make something within (for example) the sandbox gamemode. While I do think its possible that C# could be used in the same way, I do think this brings more ease-of-use to the table, and I personally also think its more fun to code in Skrypt, as it enables more freedom in some ways.
Intermediate Language Experiments
https://i.imgur.com/T85WJSa.png
Today, I've experimented with compiling parse-trees into IL (Intermediate Language code - the same code that C# compiles into). The reasoning behind this was that executing a program by going straight through a parse-tree is not very quick, and that compiling something down into byte code (essentially just a long list of simple commands) would be quicker.
My idea was to use an already existing byte code architecture so I wouldn't completely have to re-invent the wheel, so I chose IL. This would also mean I could then use the standard reflection namespace already included with C#/.NET.
After experimenting with it however, I feel like its a bit too restrictive for Skrypt. My goal now is to make up my own byte code architecture with commands that would be more fitting for what Skrypt can do.
Expression Optimizations
https://i.imgur.com/DsqB5mW.png
Expression nodes now automatically get optimized so operations on literals won't have to be redone during runtime. In the picture above you can see that it optimizes an expression such as "a = 2 + 3 * 4" into "a = 14". This also works on booleans and strings. An added bonus with this that you'll now get an error as soon as an invalid operation gets executed during compilation, instead of during runtime.
Contributors Wanted
Ever since this project took off I've gotten great feedback, ideas and other insight from a lot of people. Now that the project has grown however (it's my biggest project ever as of this post), I wanted to let other people work on it besides just me. This not only means development will be faster, but the code, performance and design will likely improve a lot. This is why I want to invite contributors to help me develop Skrypt further. Ofcourse I'd like you to have experience with C# so its certain improvements can be made, but even having people that could help with documentation or a wiki would be appreciated. If you're interested, contact me (Facepunch, GitHub or Discord if you know me there).
Improving Skrypt is fun, but making it great with other people is going to be even better.
Sorry, you need to Log In to post a reply to this thread.