Skip to content

Commit

Permalink
fix broken moonloader #71
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jan 29, 2013
1 parent 05f6a0b commit cb8cd1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
17 changes: 6 additions & 11 deletions moonscript/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ do
split, dump, get_options, unpack = _table_0.split, _table_0.dump, _table_0.get_options, _table_0.unpack
end
local lua = {
loadstring = loadstring
loadstring = loadstring,
load = load
}
local dirsep = "/"
local line_tables = require("moonscript.line_tables")
local create_moonpath
local dirsep, line_tables, create_moonpath, to_lua, moon_loader, init_loader, loadstring, loadfile, dofile
dirsep = "/"
line_tables = require("moonscript.line_tables")
create_moonpath = function(package_path)
local paths = split(package_path, ";")
for i, path in ipairs(paths) do
Expand All @@ -22,7 +23,6 @@ create_moonpath = function(package_path)
end
return concat(paths, ";")
end
local to_lua
to_lua = function(text, options)
if options == nil then
options = { }
Expand All @@ -41,10 +41,9 @@ 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
local file, file_path
local _list_0 = split(package.moonpath, ";")
for _index_0 = 1, #_list_0 do
local path = _list_0[_index_0]
Expand All @@ -65,14 +64,12 @@ end
if not package.moonpath then
package.moonpath = create_moonpath(package.path)
end
local init_loader
init_loader = function()
return insert(package.loaders or package.searchers, 2, moon_loader)
end
if not (_G.moon_no_loader) then
init_loader()
end
local loadstring
loadstring = function(...)
local options, str, chunk_name, mode, env = get_options(...)
chunk_name = chunk_name or "=(moonscript.loadstring)"
Expand All @@ -90,7 +87,6 @@ loadstring = function(...)
env
}))
end
local loadfile
loadfile = function(fname, ...)
local file, err = io.open(fname)
if not file then
Expand All @@ -100,7 +96,6 @@ loadfile = function(fname, ...)
file:close()
return loadstring(text, fname, ...)
end
local dofile
dofile = function(...)
local f = assert(loadfile(...))
return f()
Expand Down
6 changes: 4 additions & 2 deletions moonscript/init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ parse = require "moonscript.parse"
import concat, insert from table
import split, dump, get_options, unpack from require "moonscript.util"

lua = :loadstring
lua = :loadstring, :load

local *

dirsep = "/"
line_tables = require "moonscript.line_tables"
Expand Down Expand Up @@ -36,7 +38,7 @@ to_lua = (text, options={}) ->
moon_loader = (name) ->
name_path = name\gsub "%.", dirsep

file, file_path = nil, nil
local file, file_path
for path in *split package.moonpath, ";"
file_path = path\gsub "?", name_path
file = io.open file_path
Expand Down

0 comments on commit cb8cd1f

Please sign in to comment.