Scripter : My go at a language made in Lua.

[Release]

Hello. In this post I am going to present to you my go at a language made in Lua. Before any of you go porting Advance Duplicator into my new language, Please consider 2 things : 1- You would need to port all the libraries yourself, and 2- It’s not the most efficient language. I made this as a project, as to prove to myself that if I can put my mind to it, I can do moderately interesting things. Without further ado, let’s get on with the presentation.

Scripter!

Scripter is a language, conceived with Lua, to aid developers in making quick scripts. It has a customizable syntax, which is perfect for people wanting to make different “dialects” of this language. It’s in it’s early stages, so don’t expect anything big from this, but for what it’s worth it’s pretty good. It currently supports a a small range of features, but I’m sure you can find that out in due time. It is centralized around a stack, which has its pro’s and con’s.

How does it work?

I’m pretty crap at explaining with words, so I got on paint and drew a picture instead.

https://lh3.googleusercontent.com/--uWc14BiIR4/TzEnOPhNCrI/AAAAAAAAAEg/ypVnQjnCA5U/w719-h358-k/Scripter.png

Examples of work

[table=“width: 500”]


Vector ( 1 , 2 , 3 ) Pop MyVector MyVector::Print


LocalPlayer ( ) Pop Me
Me :: Name Pop MyName
print ( MyName )


_G ( ) Pop Variables
PrintTable ( Variables )

[/table]

You can also call functions from Lua

[table=“width: 500”]

[Lua]Scripter:Push( "My String" )

Scripter:Push( “print” )
Scripter:Call( 0 )[/Lua]
[Lua]Scripter:AddGlobal( “Var” , “Variable” )[/Lua]
[Lua]Scripter:AddMetaFunction( “Vector” , “Foo” ,
function( self )
print ( “foo was called” , self )
end[/Lua]

[/table]

Functions:


Scripter:Run( String, debug ) -- Run a string, with a debug paramater
Scripter:NewDataType( Name , ID ) -- Permits new datatypes
Scripter:AddGlobal( Name, Object , deletable ) -- Set Global 
Scripter:AddGlobalCustomType( Type, Name, Object , deletable ) -- Set global with type ( custom detatypes )
Scripter:RemoveGlobal( Name ) -- Delete Global
Scripter:GetGlobal( Name ) -- Get Global ( returns table { TYPE , VAR } )
Scripter:GlobalType( Name ) -- Gets the type ( number or String )
Scripter:AddMetaFunction( DATATYPE , Name, Function ) -- Meta Functions
Scripter:GetMeta( Datatype ) -- for metatables
Scripter:GetMetaFunction( DataType , Name ) -- ditto
Scripter:Push( Object ) -- Push onto stack
Scripter:Pop( ) -- get top of stack
Scripter:Ghost( Amount ) -- get top of stack without removing
Scripter:WholeStack( ) -- pop the whole stack
Scripter:EmptyStack( ) -- empty the stack
Scripter:GhostStack( ) -- Get the stack without popping
Scripter:StackSize( ) -- Amount of items on stack
Scripter:Call( Amount ) -- Call a function , last string pushed is the name of the function
Scripter:CheckType( Argument, Enum ) -- Check type ( outdated )

Scripter:SetPreTokenizeFunction( Function ) -- Like gm_preproc but worse
Scripter:InvalidatePreTokenizeFunction( ) -- remove the protokenize function that's set
Scripter:Tokenize( String ) -- Returns a preliminary interpretation
Scripter:AddToken( Token , ID ) -- Custom tokens

Scripter:AddInterpretation( Id , Args , Function ) -- Language modifying ( ID = Unique name , Args = table of token ids ,  Function )
Scripter:Interpretate( Tokens ) -- Secondary interpretation



Constants:


SCRIPTER_FUNCTION = 0;
SCRIPTER_NUMBER = 1;
SCRIPTER_STRING = 2;
SCRIPTER_TABLE = 3;
SCRIPTER_BOOLEAN = 4;
SCRIPTER_ANGLE = 5;
SCRIPTER_VECTOR = 6;

Scripter.Tokens
Scripter.DataTypes
Scripter.PreTokenize



Download:

It’s in it’s early beta, but here is the SVN:
http://custom-scripting-language.googlecode.com/svn/trunk/
Thank you for your attention


 This is opensource, don't hesitate to ask if you want to have commit permissions 

[/RELEASE]

Is there any real use for this?

It depends, It’s useful if you make it useful.

Cool I guess but I doubt anyone will use it.

To be honest I didn’t post it here so people could use it, I posted it here so people could go through the sourcecode and learn from it.

I really like this, I hope it continues

[editline]7th February 2012[/editline]

Does this need a DLL, cause it would be really useful to be able to run this clientside

It doesn’t use a DLL, It’s all coded in Lua. I’ve included a C++ file though with some shortcut functions though.

http://code.google.com/p/custom-scripting-language/source/browse/trunk/scripter.cpp

( I’m not sure I coded it correctly though, so if anyone wants to pick up the scripter.cpp file and work their magic I would be grateful, seeing as it’s not at the top of my list or things-to-do )

Cool idea. As you said, it’s more for example than use, but nevertheless a good contribution

its a cool idea, must have been a fun learning experience!

though i’d say it doesn’t have much practical use, it’s still always fun to mess about on a project like this, congrats

This literally has no use, but neither did wiremods Expression 2. Things are only useful if you find a creative way to express it. So hopefully you can expand on this and turn this into a useful and cool addon.

Expression 3.

Do we need expression 3?

Only if it had function support.

At the moment I’m focusing on the class system, and then I will focus on If conditions, and then functions.

E2 got function support a few months ago.

It might be more useful if you integrate this into Wiremod.

It can only be usefull if people adapt it to be usefull… A language o its own does nothing… Its the user that decides what it can be usefull for…

Seems overly complicated for something derived from lua.

It’s not derived from Lua, it’s simply created in Lua. You say derived as in I modify the string and use G.RunString on it, which isn’t the case. It runs the string through a library of “tokens” , applies values to them, then interprets them using predefined syntax tables.

Ironically, this seems like it’d have a far steeper learning curve than Lua itself. :v:

While it’s definitely a cool proof of concept, and undoubtedly a fun, enjoyable, and educational project for you, I can’t really see a feasible use for this in the context of Garry’s Mod.

I certainly can’t see it being used by people who want to do programming but don’t want to learn Lua because they find it too complicated, because this is even more complicated.

Still, like I said, very neat that you were able to do it.

http://dl.dropbox.com/u/8416055/FacepunchEmots/Buddy.gif

It looks complicated, but that’s the syntax I chose. You can change the syntax very easily, with functions that permit this easily.