jacob2233
|
  |
| Joined: 23 Aug 2007 |
| Total Posts: 723 |
|
|
| 08 Oct 2011 11:31 AM |
I've created such a simple script that creates simple Java class files into Lua scripts. Before you say "that's impossible!" please do keep in mind I havn't programmed an entire Java library into Lua, it's just the more simpler functions such as most geometry objects, Strings, ints, doubles, the PrintStream (output), constructors, and whether or not a method is public or privet (privet is just functions, public is transfered to _G.methodname). The Lua version prints the finished product in the output, but still has a bit of bugs in reading and coding (as I also needed a Lua library full of script functions to be paired with Java methods).
Other than that, when I get it working to an extent, I'll share it :D |
|
|
| Report Abuse |
|
|
t6e
|
  |
| Joined: 25 Dec 2010 |
| Total Posts: 587 |
|
| |
|
jacob2233
|
  |
| Joined: 23 Aug 2007 |
| Total Posts: 723 |
|
|
| 08 Oct 2011 11:39 AM |
| Once again, did I say Entire Java library? No, I said some classes. Some people need to practice reading comprehension and monitoring... |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 11:46 AM |
Jacob, GOBWEY.
~+[Praise the holy god of Java coffee beans!]+~ |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 12:06 PM |
| It would actually be pretty simple, since Java bytecode is very simple. Now, making an actual _fast_ version of it would be a very difficult task, but just interpreting the Java bytecode wouldn't be that hard. |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 12:27 PM |
| Lua doesn't have static typing..? |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 02:57 PM |
| It's easy to run a statically typed thing in a dynamically typed thing. It's running something like Lua inside of a statically typed language like Java that's harder. |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 03:00 PM |
@xLEGOx
Can I have an example? I'd like to make a kind of statically typed Lua that runs inside of Lua. It isn't a good idea to use it for normal projects, but I just want to make it for the fun. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 03:10 PM |
"It isn't a good idea to use it for normal projects, but I just want to make it for the fun."
Heh, I've tried to make such a project before _exactly because_ I wanted to use it in my real projects, to allow me greater abstraction and neatness without sacrificing performance (since the compiler back to Lua would be able to inline a lot of stuff, rather than me manually inlining things, which makes code messy)
I'll have to dig up some of my old code. I got pretty far but got lost in how to generate the code for things like: cout << (a++ + c); In a sane way. In Lua you could output it like so: cout["operator<<"]((function() local old=a; a=a+1; return old; end)() + c)) But that would be really inefficient, so you have to have some complicated code to manage stuff like that in a good way, if you want to have expressions with side-effects like that. |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 03:14 PM |
@xLEGOx
You mean it is possible to make it statically typed without losing much performance at all?
Of course, the best would be if you could even use that to GAIN performance, but since we want to run it inside of Lua, that's impossible. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 03:19 PM |
"You mean it is possible to make it statically typed without losing much performance at all? ... but since we want to run it inside of Lua, that's impossible."
Quite the contrary, it's very possible to _gain_ performance by doing stuff that way, even in Lua.
The thing is you have to compile down to Lua bytecode, not just down to Lua code, which makes things significantly more complicated, especially if you want support for generics. |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 03:25 PM |
You mean I could literally make my own compiler that runs in Lua? :O!
But... Lua's compiler would probably be more optimized than mine, wouldn't it? |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 03:34 PM |
Supposing I write a compiler in Lua and precompile it. That compiler is able to compile code that is exactly like normal Lua code, except that it is statically typed. Could I gain speed using a such compiler? I mean, Lua's compiler is not written in Lua, while mine is, so I guess mine would have to be REALLY optimized to really gain speed...
Plus I guess writing a Lua compiler requires a lot of work.. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 03:35 PM |
| Lua's compiler will definitely run at least 100x faster than yours. However, that doesn't matter since you can run your Lua compiler and turn your scripts into normal Lua byte-code chunks whenever you want, rather than having to do it at run-time. So in the end, you won't even take a performance hit there. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 03:37 PM |
"Plus I guess writing a Lua compiler requires a lot of work.."
A lot but doable. If I'd finished mine I'd estimate it would have ended up at about 8000 lines of code. When I stopped working on it it was at about 5000 lines. |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 04:02 PM |
| But to maintain static typing, you'd need to constantly be checking for the type of every variable, no? |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Oct 2011 04:05 PM |
"But to maintain static typing, you'd need to constantly be checking for the type of every variable, no?"
Not at all. If a normal executable doesn't have to do that, why would the Lua interpreter have to do that?
Just think about it. If you know something is an int, and your compiler's syntax enforces that you can only use an int somewhere, then you don't have to check that something is an int at run-time, because it _can only_ be an int if the code got to where it is in the first place. |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 04:12 PM |
"But to maintain static typing, you'd need to constantly be checking for the type of every variable, no?"
Nope. The compiler deals with that. You don't need to check it at run time. The compiler checks everything and tells you if there is an error. If there isn't, you can run the code. No need to verify if the type of the variable is the correct one, the compiler ALREADY did it.
@xLEGOx
"Lua's compiler will definitely run at least 100x faster than yours. However, that doesn't matter since you can run your Lua compiler and turn your scripts into normal Lua byte-code chunks whenever you want, rather than having to do it at run-time. So in the end, you won't even take a performance hit there."
Should've of thought about it. :O
If I precompile my scripts, there's no problem anymore with the speed of my compiler! And thus, I could even literally write my compiler in another language!
So if I understand, what I could do is make my own Lua compiler that requires the code to be statically typed and that generates more optimized bytecode than the one generated by the real compiler... But studying Lua bytecode and writing my own compiler requires a lot of work... on the other side, it could provide a real improvement (not THAT huge, but it would still be a _real_ improvement) to the speed of Lua code, and would even make it more clear, since statically typed code usually looks better than dynamically typed code..
And just so I can get an idea, can I see some code from your compiler, even if you didn't finish it? ;o |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 04:20 PM |
| Is there a computational cost to the type of a variable changing, due to dynamic typing, during run-time? |
|
|
| Report Abuse |
|
|
|
| 08 Oct 2011 04:26 PM |
@bunnybunn
Well, I'm not an expert on that question, but I can tell you that for the compiler, being able to know the type of a variables is useful, since it makes it able to produce more optimized machine code. |
|
|
| Report Abuse |
|
|
jacob2233
|
  |
| Joined: 23 Aug 2007 |
| Total Posts: 723 |
|
|
| 09 Oct 2011 09:42 PM |
Since you guys seem to be wondering what it is exactly, it's a Java decompiler that translates the Java file bytecode into Human readable Java Lua that I made in Visual Basic on Microsoft Visual Studio 2010 (Don't as how I got that program :D). It does take the bytecode and translate it back into human readable code. From there I am able to pair everything written with an equal method in Lua, I have so far programmed all of ROBLOX's Lua language into the program (thank god for the object browser!) and I have taken more complex Classes and paired them with an equal Lua Class. The program then tests the Lua script in a compiler (which was a pain to do!) and if any errors are given it prints those in a Human output for the user to read. I am working on a logic system that takes methods, Classes, or anything else that looks like a familure Lua code, so I don't have to program the Java library myself (cause that would take years, litterally!).
Confused? It takes a Java class file, decompiles it, pairs the Human Readable code with a Lua equivlent, tests that Lua code, and show's you the code and the output.
Java code: Rectangle r = new Rectangle(5, 10, 40, 60); g2.draw(r);
Lua's equivlent: local r = Instance.new("Frame") r.Name = "r" r.Size = UDim2.new(width, 0, height, 0) r.BackgroundTransparency = 1.0 r.Position = UDim2.new(0, 5, 0, 10) r.Size = UDim2.new(0, 40, 0, 60) r.Parent = gui --The parent isn't normally given, also this line isn't written until g2.draw(r); is written.
That was part of an output I got with the translator so far. |
|
|
| Report Abuse |
|
|
jacob2233
|
  |
| Joined: 23 Aug 2007 |
| Total Posts: 723 |
|
|
| 09 Oct 2011 09:48 PM |
| I could create a Lua script that does something simular, but it would be terribly limited in performance. Meaning it wouldn't translate everything. But I'm wanting to finish my Windows program before making a Lua-only code version. |
|
|
| Report Abuse |
|
|
wii4
|
  |
| Joined: 27 Nov 2007 |
| Total Posts: 929 |
|
|
| 09 Oct 2011 09:53 PM |
| Java is the heart of all evil. it created such addicting games like m1 n 3 cr4 ft not to say that it isn't good its just java isn't really favourable and i don't see why you would want to translate something from java to lua? it would be much easier just to rewrite it in lua instead of writting an entire translator. it wouldn't take as long and you would be less ceceptible to errors. |
|
|
| Report Abuse |
|
|
jacob2233
|
  |
| Joined: 23 Aug 2007 |
| Total Posts: 723 |
|
|
| 09 Oct 2011 09:57 PM |
| Many of my Java works are actually enjoyable. Infact, my Maze Generator place is a copy of a Java work I did but manually translated to Lua (which was easy since it is mainly an algorithm) but I want to translate bigger Java files and games of mine. Java is also used by Sony Pictures and Google Maps :P |
|
|
| Report Abuse |
|
|
jacob2233
|
  |
| Joined: 23 Aug 2007 |
| Total Posts: 723 |
|
|
| 13 Oct 2011 10:51 PM |
Finished! I have finally completed a working program that utilizes the Java language programmed on your computer, reads the Class (rather decodes it first and reads the human readable code) then studies the the programmed API on the identifiers, methods, classes, constructors, etc...Then it translates the knewly studied Java file into Lua by pairing similar functions, variables, methods, constructors and so on. After it built a code file in Lua, it runs an output (almost exactly like the one ROBLOX uses for convience, but different method I assume) and it either corrects its own simple mistakes and gives you the code, or corrects simple mistakes and gives you the output and Human-Readable Lua code for you to debug.
Works most the time, but I want to now create a Lua file that does the same thing in ROBLOX. It would work by reading the bytecode of a specific file on YOUR computer only, and does the same work and prints a script in your output box. I've seen similar works on ROBLOX that read files on your computer, so I want to give this a try.
What's the point of all this? Well, I'm an avide Java programmer, and I sometimes want to convert Java into Lua to show ROBLOXians. But sadly I don't want to spend hours or days manually converting the codes.
ToDo: Create a vice versa translater in my program that converts Lua to Java, although that would be much more buggier than Java to Lua, cause your going from a small library to a larger library of more infinite possiblities to do the same tasks. I wouldn't expect to finish it. |
|
|
| Report Abuse |
|
|