js2lua.lua

Fri, 15 Oct 2010 15:17:17 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 15 Oct 2010 15:17:17 +0100
changeset 0
b2e55f320d48
permissions
-rw-r--r--

Initial commit

#!/usr/bin/env lua

local jslex = require "lib.jslex"
local js2lua = require "lib.js2lua"

local stream = jslex.new_stream(io.open(arg[1]));

local list = {};

local i, token_type, token_value = 0, stream.get_token();
while token_type do
	i = i + 1;
	list[i] = { type = token_type, value = token_value };
	
--	print("Line "..(stream.line or 1)..":", token_type, token_value);
	token_type, token_value = stream.get_token();
end

io.stderr:write("js2lua: Translating...\n");
local d = {};
local function w(t) table.insert(d, t); end
js2lua(list, w);
io.stderr:write("===== Result ======\n", table.concat(d), "\n===== ====== =====\n");
io.stderr:write("js2lua: Running...\n");
assert(loadstring(table.concat(d)))();

mercurial