lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Phil,

I`ve written similar code, where you write everyhing a web pages might need in lua and it compiles to html/css/js.

Theres 2 approaches really:

1) parse lua source and output javascript
2) write a luavm in javascript

We chose chose 1) purely for performance (warranted or not...) as it seemed the simpler choice at the time. Hindsight.. would consider 2) more carefully as 1) means using only a subset of the langauge.. and.. you have to be aware your writing javascript in lua.. We used lbc to do the trick, and its a fairly straight forward process - a few pages of code. Its far from perfect but supports enough of the language that theres no major mental switch between the subset and full spec.

If you want any lua code to run 2) is the only real option. And you code this up let me know!

Cheers,
Aaron

Phil Deets wrote:
Hello, I have been thinking about writing a Lua to JavaScript translator. The main use case would simply be to provide an alternative language for the web. You would just have to run the translator before you use the script.

This would be different than the lua2js which already exists on LuaForge since I would want to make it work in all cases with the only restrictions being on what modules can be used. I think lua2js only does a superficial translation. For example, I don't think it handles using functions as an index into a table.

I do not have a goal of making the output readable. In fact I might purposely obfuscate the output to hinder reverse-engineering efforts of the translated code.

The approach that seems the easiest to me is to run the Lua source through luac.exe and use the output of luac as the input of the translator. This way I don't have to worry about lexing or parsing. I also could have a smaller range of inputs to worry about; there would only be the 38 types of instructions to translate. The down-side to this approach is that the format of the luac output could change significantly between versions.

Now for my questions:
Is this already being work on?
Can you think of any major problems that would prevent the approach described in the previous paragraph from working?
Can you think of a better approach?

Thanks,
Phil

P.S. I couldn't find a search feature for the mailing list archive; so sorry if this has already been discussed.