| 1 | #!/usr/bin/env lua |
| 2 | |
| 3 | local jslex = require "lib.jslex" |
| 4 | local js2lua = require "lib.js2lua" |
| 5 | |
| 6 | local stream = jslex.new_stream(io.open(arg[1])); |
| 7 | |
| 8 | local list = {}; |
| 9 | |
| 10 | local i, token_type, token_value = 0, stream.get_token(); |
| 11 | while token_type do |
| 12 | i = i + 1; |
| 13 | list[i] = { type = token_type, value = token_value }; |
| 14 | |
| 15 | -- print("Line "..(stream.line or 1)..":", token_type, token_value); |
| 16 | token_type, token_value = stream.get_token(); |
| 17 | end |
| 18 | |
| 19 | io.stderr:write("js2lua: Translating...\n"); |
| 20 | local d = {}; |
| 21 | local function w(t) table.insert(d, t); end |
| 22 | js2lua(list, w); |
| 23 | io.stderr:write("===== Result ======\n", table.concat(d), "\n===== ====== =====\n"); |
| 24 | io.stderr:write("js2lua: Running...\n"); |
| 25 | assert(loadstring(table.concat(d)))(); |