Jump to content




Midnightas' Lua Preprocessor (Adds many new features to Lua)

utility java lua

25 replies to this topic

#1 Midnightas

  • Members
  • 44 posts

Posted 18 December 2016 - 03:40 PM

MLua
A preprocessor that adds support for OOP, lambda, and some more upcoming things.

Syntax
Downloads

Differences between this and the old version:
- No foreach, since Lua has it's own
- None of it's own APIs, that's not something a preprocessor should have
- Classes with no constructors are non-instantiable
- No switch statement (yet)

old deprecated version

Edited by Midnightas, 19 November 2017 - 10:26 AM.


#2 Midnightas

  • Members
  • 44 posts

Posted 19 December 2016 - 07:12 AM

Uploaded beta 1.1. Changes in the changelog.
Also finally documented the lambda feature that was there from the start.

#3 exosceleton

  • Members
  • 52 posts
  • LocationUmm... Mars.

Posted 19 December 2016 - 08:32 AM

This is well and truly amazing. Great job.

#4 jv110

  • Members
  • 108 posts
  • LocationIn front of my PC

Posted 19 December 2016 - 06:55 PM

Does it really force you to use semicolons?

Also, the name of the ?: operator is conditional operator, not ternary operator. "Ternary" just says it has 3 arguments.

#5 Midnightas

  • Members
  • 44 posts

Posted 19 December 2016 - 08:19 PM

View Postjv110, on 19 December 2016 - 06:55 PM, said:

Does it really force you to use semicolons?

Also, the name of the ?: operator is conditional operator, not ternary operator. "Ternary" just says it has 3 arguments.
Yes, it does currently. Although this is beta, so this may change later to be optional.
And the name of the operator has both names, it's just that "ternary operator" is used by the minority.

#6 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 19 December 2016 - 09:23 PM

View PostMidnightas, on 19 December 2016 - 08:19 PM, said:

View Postjv110, on 19 December 2016 - 06:55 PM, said:

Does it really force you to use semicolons?

Also, the name of the ?: operator is conditional operator, not ternary operator. "Ternary" just says it has 3 arguments.
Yes, it does currently. Although this is beta, so this may change later to be optional.
And the name of the operator has both names, it's just that "ternary operator" is used by the minority.

How are you "preprocessing" this exactly? Is it actually analyzing the code, building an AST and then "rebuilds" Lua source from that, or does it "just" replace some stuff with something else?

After seeing this I decided to work on something a bit like this too: This compiles from a custom language to Lua, though (and isn't feature complete at all + really needs to be redone)

Edited by H4X0RZ, 19 December 2016 - 09:30 PM.


#7 Midnightas

  • Members
  • 44 posts

Posted 19 December 2016 - 09:31 PM

View PostH4X0RZ, on 19 December 2016 - 09:23 PM, said:

View PostMidnightas, on 19 December 2016 - 08:19 PM, said:

View Postjv110, on 19 December 2016 - 06:55 PM, said:

Does it really force you to use semicolons?

Also, the name of the ?: operator is conditional operator, not ternary operator. "Ternary" just says it has 3 arguments.
Yes, it does currently. Although this is beta, so this may change later to be optional.
And the name of the operator has both names, it's just that "ternary operator" is used by the minority.

How are you "preprocessing" this exactly? Is it actually analyzing the code, building an AST and then "rebuilds" Lua source from that, or does it "just" replace some stuff with something else?

After seeing this I decided to work on something a bit like this too: This compiles from a custom language to Lua, though (and isn't feature complete at all + really needs to be redone)
This uses ANTLR4. Which yes, It does built an AST and rebuilds a Lua file.
In ANTLR4 you just need to create a grammar file, and then it creates the lexer for you. The parsing is your own work, though.

Edited by Midnightas, 19 December 2016 - 09:32 PM.


#8 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 19 December 2016 - 09:41 PM

Oh, that sounds interesting! I once tried to use ANTLR but I always failed, either at writing the grammar, or at compiling the AST.

Well done!

#9 InternetUnexplorer

  • Members
  • 24 posts
  • Locationno

Posted 19 December 2016 - 10:24 PM

View PostH4X0RZ, on 19 December 2016 - 09:41 PM, said:

Oh, that sounds interesting! I once tried to use ANTLR but I always failed, either at writing the grammar, or at compiling the AST.
Well done!
There are plenty of grammars already written for Antlr4. Such as this one:
https://github.com/a...ster/lua/Lua.g4

Excuse the formatting, I'm on mobile.

#10 Midnightas

  • Members
  • 44 posts

Posted 19 December 2016 - 10:27 PM

View PostInternetUnexplorer, on 19 December 2016 - 10:24 PM, said:

View PostH4X0RZ, on 19 December 2016 - 09:41 PM, said:

Oh, that sounds interesting! I once tried to use ANTLR but I always failed, either at writing the grammar, or at compiling the AST.
Well done!
There are plenty of grammars already written for Antlr4. Such as this one:
https://github.com/a...ster/lua/Lua.g4

Excuse the formatting, I'm on mobile.
Oh wow, how did I forget about that repo? That would've saved me so much time, and this compiler still does not feature many of Lua's syntax features.

#11 Pyuu

  • Members
  • 203 posts

Posted 19 December 2016 - 11:47 PM

Awesome program! You should use Github or something else to host though. The admins don't like closed-source here.

#12 jv110

  • Members
  • 108 posts
  • LocationIn front of my PC

Posted 20 December 2016 - 12:59 AM

It's not hard to write a Lua grammar without semicolons. In fact, I find it even harder to write a grammar with semicolons

#13 Midnightas

  • Members
  • 44 posts

Posted 20 December 2016 - 07:28 AM

View PostPyuu, on 19 December 2016 - 11:47 PM, said:

Awesome program! You should use Github or something else to host though. The admins don't like closed-source here.
Thank you! And yes, I've added a link to the GitHub repo.

#14 Midnightas

  • Members
  • 44 posts

Posted 20 December 2016 - 03:53 PM

Uploaded 1.12. Changes in the changelog.

#15 Midnightas

  • Members
  • 44 posts

Posted 20 December 2016 - 07:41 PM

View Postjv110, on 20 December 2016 - 12:59 AM, said:

It's not hard to write a Lua grammar without semicolons. In fact, I find it even harder to write a grammar with semicolons
I did not say It's hard. It's a design choice. As I have said, this is subject to change.

#16 Pyuu

  • Members
  • 203 posts

Posted 22 December 2016 - 01:30 AM

This project inspired me to write something earlier... would you mind if I post a Pure Lua implementation of this (as in converting the Java program to Lua) if I can get it to work? (I'll follow the terms as stated in the https://creativecomm...nses/by-sa/4.0/ license you provided in your github.) This is a very cool project and I'd love to build on it, but I don't like Java personally.

Also, https://github.com/l...reproc/issues/1 having an issue with this. Using the latest build btw.

Edited by Pyuu, 22 December 2016 - 01:49 AM.


#17 Midnightas

  • Members
  • 44 posts

Posted 22 December 2016 - 07:25 AM

Added version 1.13.

View PostPyuu, on 22 December 2016 - 01:30 AM, said:

This project inspired me to write something earlier... would you mind if I post a Pure Lua implementation of this (as in converting the Java program to Lua) if I can get it to work? (I'll follow the terms as stated in the https://creativecomm...nses/by-sa/4.0/ license you provided in your github.) This is a very cool project and I'd love to build on it, but I don't like Java personally.

Also, https://github.com/l...reproc/issues/1 having an issue with this. Using the latest build btw.
No, I don't mind! Go for it, although converting everything in the parser package will be a pain, since it was machine-generated.

Edited by Midnightas, 22 December 2016 - 07:25 AM.


#18 Midnightas

  • Members
  • 44 posts

Posted 02 January 2017 - 03:40 PM

Had to change the name to something else as requested on GitHub.

#19 Midnightas

  • Members
  • 44 posts

Posted 10 March 2017 - 06:29 PM

I'm adding in the switch statement but I don't know how to make it look Lua-like.

This is what I've got so far:
switch someNumber if
  case 1 then
   
  end
  case 2 then
   
  end
end


#20 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 10 March 2017 - 06:47 PM

Why only numbers? Would be cool to see something really powerful, like all data types mixed together, that would be really useful!
Also I'd say drop the 'if' at the end of the line, but we'll see what others think of it.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users