This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mendax's profile picture

SScript: A simple alternative to Lua

Started by Mendax, 25 November 2012 - 08:03 PM
Mendax #1
Posted 25 November 2012 - 09:03 PM
About 6 hours before posting this, I decided I would dig up my old work, rewrite it completely, add a little SKS-OS flair and see what I got.
The result is this.
Now, I have an example program here. There is a Lua example and an SScript example.
Simple FTP program:
Lua:
Spoiler

-- Interpreted in SScript by ShadowKatStudios
function SEND()
print 'ID:'
SENDID = read()
print 'PATH:'
PATH = read()
file = fs.open(PATH,"r")
CONTENT = file.readAll()
file.close()
rednet.send(tonumber(SENDID),CONTENT)
end
function RECEIVE()
print 'ID:'
RECEIVEID = read()
print 'PATH'
PATH = read()
ID,CONTENT = rednet.receive()
file =  fs.open(PATH,"w") file.write(CONTENT) file.close()
end
print 'SEND OR RECEIVE (S/R):'
CHOICE = read()
if CHOICE == "S" then SEND() end
if CHOICE == "R" then RECEIVE() end
SScript
Spoiler

LABEL
SEND

ECHO
ID:
INPUT
SENDID
ECHO
PATH:
INPUT
PATH
READFILE
PATH
CONTENT
NETSEND
SENDID
CONTENT
ENDLABEL

LABEL
RECEIVE

ECHO
ID:
INPUT
RECEIVEID
ECHO
PATH
INPUT
PATH
NETRECEIVE
ID
CONTENT
WRITEFILE
PATH
CONTENT
ENDLABEL

ECHO
SEND OR RECEIVE (S/R):
INPUT
CHOICE
IF
CHOICE
==
"S"
SEND

IF
CHOICE
==
"R"
RECEIVE

Download is HERE.
Sammich Lord #2
Posted 25 November 2012 - 09:48 PM
So it is basically one operation per line? The code isn't very well written though. You basically have a ton of elseif statements to see what it is. I suggest remaking this and adding syntax similar to Java or C#. However, if this is your first try, it is pretty good.
billysback #3
Posted 25 November 2012 - 09:53 PM
Syntax "like java or c#" is kinda hard to make, it's a reasonably complex language, for one thing you have to start off by ignoring all lines, then you ignore almost all spaces as white space is irrelevant apart from when inside a string, then you have to find the beginning of statements and ends of them, as these won't be bale to be separated by a semi-colon, then you can split the code to be run if the statement is matched by ";" and run the code by each line, looking for key operators (like "=" or ".") to decide what you need to do with the line…

On topic:
the syntax is pretty cool :D/>/>
Sammich Lord #4
Posted 25 November 2012 - 10:12 PM
Syntax "like java or c#" is kinda hard to make, it's a reasonably complex language, for one thing you have to start off by ignoring all lines, then you ignore almost all spaces as white space is irrelevant apart from when inside a string, then you have to find the beginning of statements and ends of them, as these won't be bale to be separated by a semi-colon, then you can split the code to be run if the statement is matched by ";" and run the code by each line, looking for key operators (like "=" or ".") to decide what you need to do with the line… On topic: the syntax is pretty cool :D/>/>/>
Well when you say it like that… seems complex. But it would be a lot easier to read if it was not just one command per line.
Mendax #5
Posted 26 November 2012 - 01:37 AM
Yeah, I did make it one operation per line, and for a reason too. This way, it needs no external libraries, no custom APIs, and less space. If you have a problem with how I did this, tell someone who cares.
Sammich Lord #6
Posted 26 November 2012 - 01:50 AM
Yeah, I did make it one operation per line, and for a reason too. This way, it needs no external libraries, no custom APIs, and less space. If you have a problem with how I did this, tell someone who cares.
I am actually writing a language like this. But I am working on have multiple operations per line, so I have to do a lot of tricky string.sub and loops.
Mendax #7
Posted 26 November 2012 - 02:39 AM
Lucky you. I doubt you can keep it in one file.
Sammich Lord #8
Posted 26 November 2012 - 03:30 AM
Lucky you. I doubt you can keep it in one file.
Why would I need it to be in one file?
Tiin57 #9
Posted 26 November 2012 - 03:33 AM
Lucky you. I doubt you can keep it in one file.
Why would I need it to be in one file?
He's bragging that his language is coded in one file. I think.
tommyroyall #10
Posted 26 November 2012 - 03:39 AM
This seems to be based off of RedScript . . . . CLI epicness :3. Good job man :D/>/>.
Sammich Lord #11
Posted 26 November 2012 - 03:42 AM
Lucky you. I doubt you can keep it in one file.
Why would I need it to be in one file?
He's bragging that his language is coded in one file. I think.
I like my code to be spread out. Easier to look at it if it is not all in one file that is two thousand lines long.
Matt21 #12
Posted 26 November 2012 - 04:04 AM
Nice!
Cranium #13
Posted 26 November 2012 - 05:03 AM
I agree, Human. The first program I ever released is over 2500 lines long. It does get the job done, but the code is as ugly as -yo momma joke snipped-
Sammich Lord #14
Posted 26 November 2012 - 05:12 AM
After thinking about it, this isn't a scripting language, it is more of a wrapper for Lua.
Tiin57 #15
Posted 26 November 2012 - 05:18 AM
-snip- I like my code to be spread out. Easier to look at it if it is not all in one file that is two thousand lines long.
Exactly how I feel.
billysback #16
Posted 26 November 2012 - 05:24 AM
After thinking about it, this isn't a scripting language, it is more of a wrapper for Lua.
Isn't a wrapper something that externally adds to the wrapped program, so you run the wrapper and it, in turn, runs the original program but under different conditions and modifies things like responses from the program and input in to the program, it adds a buffer to the program essentially usually to create a easier interface.

This doesn't create a easier interface and it doesn't improve upon lua or anything like that, this just converts lines in to lua code…
Mendax #17
Posted 26 November 2012 - 09:55 AM
This seems to be based off of RedScript . . . . CLI epicness :3. Good job man :D/>/>/>.
Not quite, but it's not all that different. The syntax is just a little… Different.
Mendax #18
Posted 30 November 2012 - 11:59 PM
This thread is now redundant, as SScript 2.0 is almost ready.
Cruor #19
Posted 01 December 2012 - 12:00 AM
Locked as requested.