Create a lua interpreter
Started by Varscott11, Jun 22 2016 06:17 PM
8 replies to this topic
#1
Posted 22 June 2016 - 06:17 PM
I'm currently working on a program called UNET, which is a very complex internet service. When it comes to the servers, I want to make it so that the web designer, can create his/her website using a lua interpreter. This will ease the pain of using lua to create things like the gui, by simply converting the users simplified code to it's lua equivalent. Problem is, I have no idea how to go about doing this. Anyone have any ideas?
#2
Posted 22 June 2016 - 07:06 PM
You want to make a lua IDE? I'm not exactly certain what you're asking for.
#3
Posted 22 June 2016 - 08:45 PM
Are you aiming to make something like HTML? A language that lets a person describe a GUI, that you then want to convert into Lua code so it draws and updates and stuff?
#4
Posted 22 June 2016 - 09:36 PM
I think what they want to do is to have a Lua interpreter interpret Lua code and generate html&css from that.
#5
Posted 24 June 2016 - 04:22 PM
I want to do exactly what Exerro said. Use it to convert mainly simplified gui code into lua form.
Any help is appreciated
Any help is appreciated
#6
Posted 24 June 2016 - 05:36 PM
Varscott11, on 24 June 2016 - 04:22 PM, said:
I want to do exactly what Exerro said. Use it to convert mainly simplified gui code into lua form.
Any help is appreciated
Any help is appreciated
Instead of writing your own language, you could use the flexibility of Lua to make it work the way you want. I'll give you an example in a minute.
#7
Posted 25 June 2016 - 12:47 PM
Well, as H4X0RZ said, making some fancy Lua interface is probably better. Lua lets you do some nice syntactical things:
However, if you're set on writing a custom language, you'll probably want to follow these steps:
Lexing - Breaking some input text into a series of 'tokens'. A token is some object in the text, like a word or a number. If you get the lexing right, you won't have to worry about whitespace, and you'll easily be able to parse (the next step) the input.
Parsing - Converting the tokens into an AST. An AST (abstract syntax tree) is a format that represents your language. For HTML, you might want something like:
Once you've parsed it, it'll be much easier to deal with. You can then get around to code generation. If I were you, I'd make some form of GUI API or use an existing one. Then your code generation can hook into that, for example if the user wants a button at (5, 5), you could just generate the code:
There are a few GUI APIs these lying around on the forums, which you'd be able to use.
new "button" at (5, 5) {
text = "Hello!";
}
style "dark" {
["background-colour"] = colours.grey;
}
However, if you're set on writing a custom language, you'll probably want to follow these steps:
Lexing - Breaking some input text into a series of 'tokens'. A token is some object in the text, like a word or a number. If you get the lexing right, you won't have to worry about whitespace, and you'll easily be able to parse (the next step) the input.
Parsing - Converting the tokens into an AST. An AST (abstract syntax tree) is a format that represents your language. For HTML, you might want something like:
{ type = "h1", attributes = {}, body = {
{ type = "span", body = "Hello world!" };
{ type = "a", attributes = { href = "some-url" }, body = "a link ooooh" };
} }
Once you've parsed it, it'll be much easier to deal with. You can then get around to code generation. If I were you, I'd make some form of GUI API or use an existing one. Then your code generation can hook into that, for example if the user wants a button at (5, 5), you could just generate the code:
GUIAPI.addButton( 5, 5 )
There are a few GUI APIs these lying around on the forums, which you'd be able to use.
#8
Posted 26 June 2016 - 01:34 AM
Thanks for the reply Exerro! This helped alot. I have begun making some basic commands for the user to use while keeping in mind the parsing method.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











