lua 5.2 support

This commit is contained in:
leaf corcoran 2013-01-02 13:53:31 -08:00
parent e99161359a
commit 1f8b54da3c
7 changed files with 34 additions and 16 deletions

View File

@ -1,6 +1,5 @@
local moon = require("moonscript")
local util = require("moonscript.util")
require("lpeg")
local lpeg = require("lpeg")
local concat, insert = table.concat, table.insert
local split, pos_to_line = util.split, util.pos_to_line
local user_error
@ -61,7 +60,7 @@ truncate_traceback = function(traceback, chunk_func)
end
local rewrite_traceback
rewrite_traceback = function(text, err)
local line_tables = moon.line_tables
local line_tables = require("moonscript.line_tables")
local V, S, Ct, C = lpeg.V, lpeg.S, lpeg.Ct, lpeg.C
local header_text = "stack traceback:"
local Header, Line = V("Header"), V("Line")

View File

@ -1,8 +1,7 @@
moon = require "moonscript"
util = require "moonscript.util"
require "lpeg"
lpeg = require "lpeg"
import concat, insert from table
import split, pos_to_line from util
@ -43,7 +42,7 @@ truncate_traceback = (traceback, chunk_func="moonscript_chunk") ->
concat traceback, "\n"
rewrite_traceback = (text, err) ->
line_tables = moon.line_tables
line_tables = require "moonscript.line_tables"
import V, S, Ct, C from lpeg
header_text = "stack traceback:"

View File

@ -1,4 +1,3 @@
module("moonscript", package.seeall)
local compile = require("moonscript.compile")
local parse = require("moonscript.parse")
local concat, insert = table.concat, table.insert
@ -10,8 +9,8 @@ end
local lua = {
loadstring = loadstring
}
dirsep = "/"
line_tables = { }
local dirsep = "/"
local line_tables = require("moonscript.line_tables")
local create_moonpath
create_moonpath = function(package_path)
local paths = split(package_path, ";")
@ -23,6 +22,7 @@ create_moonpath = function(package_path)
end
return concat(paths, ";")
end
local to_lua
to_lua = function(text, options)
if options == nil then
options = { }
@ -41,6 +41,7 @@ to_lua = function(text, options)
end
return code, ltable
end
local moon_loader
moon_loader = function(name)
local name_path = name:gsub("%.", dirsep)
local file, file_path = nil, nil
@ -71,6 +72,7 @@ end
if not _G.moon_no_loader then
init_loader()
end
local loadstring
loadstring = function(str, chunk_name, options)
if options == nil then
options = nil
@ -86,6 +88,7 @@ loadstring = function(str, chunk_name, options)
end
return lua.loadstring(code, chunk_name or "=(moonscript.loadstring)")
end
local loadfile
loadfile = function(fname, options)
if options == nil then
options = nil
@ -98,7 +101,18 @@ loadfile = function(fname, options)
file:close()
return loadstring(text, fname, options)
end
local dofile
dofile = function(fname, options)
local f = assert(loadfile(fname))
return f()
end
return {
_NAME = "moonscript",
to_lua = to_lua,
moon_chunk = moon_chunk,
moon_loader = moon_loader,
dirsep = dirsep,
dofile = dofile,
loadfile = loadfile,
loadstring = loadstring
}

View File

@ -1,6 +1,4 @@
module "moonscript", package.seeall
compile = require "moonscript.compile"
parse = require "moonscript.parse"
@ -9,11 +7,8 @@ import split, dump from require "moonscript.util"
lua = :loadstring
export to_lua, moon_chunk, moon_loader, dirsep, line_tables
export dofile, loadfile, loadstring
dirsep = "/"
line_tables = {}
line_tables = require "moonscript.line_tables"
-- create moon path package from lua package path
create_moonpath = (package_path) ->
@ -82,3 +77,9 @@ dofile = (fname, options) ->
f = assert loadfile fname
f!
{
_NAME: "moonscript"
:to_lua, :moon_chunk, :moon_loader, :dirsep, :dofile, :loadfile,
:loadstring
}

View File

@ -0,0 +1 @@
return { }

View File

@ -0,0 +1 @@
{}

View File

@ -1,7 +1,7 @@
local util = require"moonscript.util"
require"lpeg"
local lpeg = require"lpeg"
local debug_grammar = false
@ -13,6 +13,9 @@ local ntype = types.ntype
local dump = util.dump
local trim = util.trim
local getfenv = util.getfenv
local setfenv = util.setfenv
local Stack = data.Stack
local function count_indent(str)