PaulBernier / castl

JavaScript to Lua compiler with runtime library.
GNU Lesser General Public License v3.0
372 stars 33 forks source link

success story with ASCIIMathML.js — thanks! :) #19

Open akavel opened 7 years ago

akavel commented 7 years ago

Wanted to write by email, but given that there are two small tweaks worth reporting, I decided to write via github.

So, firstly, big thanks for the tool! :) I used it to successfully translate the ASCIIMathML.js tool from JS to Lua 5.2. I'm hoping to use it to build a math rendering feature into the SILE typesetter.

As an aside, I had to do two tiny but really tricky tweaks after the initial port:

  1. x = {} (function() end) is treated by Lua as an attempt to call an array; I had to insert a comma ; to fix such a situation and it took me some time to realize this was the reason for a weird Lua error message;
  2. castl.sort is potentially slightly broken when translating JS sort to Lua table.sort — Lua expects the compare func to implement <, while castl.sort resulted in <= semantics in my case. I tweaked the translated code to fix the issue in my code, as it was easier for me in this case than tweaking castl.sort.

Thanks again!

EDIT: added link to the fix I did regarding castl.sort; forgot to add the link originally :/

PaulBernier commented 7 years ago

Hi Mateusz,

Thanks a lot for your feedback! And wow that's great what you did with ASCIIMathML. About creating a math rendering feature on top of it, without any insight, I'd be slightly worried about what could be the resulting performances (especially if you're going to use regular Lua VM and not the JIT). But that's a great experiment you are conducting and I'm happy to hear about it :)

For 1. upfront it looks like it should be pretty easy to fix. What is the JS code that lead to this weird Lua code?

For 2. that looks more tricky, I'd have to deep dive, but I remember I already had trouble back in the time with sorting... not sure it's easily fixable...

akavel commented 7 years ago

Re. 1: asciimath.js, l.32-34

Re. 2: It shouldn't be really hard to observe, if you copy the core logic from what happened in my code into some unit test. Related areas of code:

PaulBernier commented 7 years ago

For 1. I just tried to transpile asciimath.js with the latest version of castl and the resulting output had a semi-colon after _obj({}). I'm not sure why it didn't happen in your case :/