js2lua.lua

changeset 0
b2e55f320d48
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/js2lua.lua	Fri Oct 15 15:17:17 2010 +0100
@@ -0,0 +1,25 @@
+#!/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