restore argument, make more moonscripty, add spec #176

This commit is contained in:
leaf corcoran 2015-03-16 23:54:33 -07:00
parent f08477d3d6
commit 0ccd5e3ca4
3 changed files with 38 additions and 13 deletions

View File

@ -18,14 +18,30 @@ local dirsep, line_tables, create_moonpath, to_lua, moon_loader, loadstring, loa
dirsep = "/"
line_tables = require("moonscript.line_tables")
create_moonpath = function(package_path)
local moonpaths = { }
local _list_0 = split(package.path, ";")
for _index_0 = 1, #_list_0 do
local path = _list_0[_index_0]
local p = path:match("^(.-)%.lua$")
if p then
insert(moonpaths, p .. ".moon")
local moonpaths
do
local _accum_0 = { }
local _len_0 = 1
local _list_0 = split(package_path, ";")
for _index_0 = 1, #_list_0 do
local _continue_0 = false
repeat
local path = _list_0[_index_0]
local prefix = path:match("^(.-)%.lua$")
if not (prefix) then
_continue_0 = true
break
end
local _value_0 = prefix .. ".moon"
_accum_0[_len_0] = _value_0
_len_0 = _len_0 + 1
_continue_0 = true
until true
if not _continue_0 then
break
end
end
moonpaths = _accum_0
end
return concat(moonpaths, ";")
end
@ -134,5 +150,6 @@ return {
dirsep = dirsep,
dofile = dofile,
loadfile = loadfile,
loadstring = loadstring
loadstring = loadstring,
create_moonpath = create_moonpath
}

View File

@ -13,10 +13,10 @@ line_tables = require "moonscript.line_tables"
-- create moon path package from lua package path
create_moonpath = (package_path) ->
moonpaths = {}
for path in *split package.path, ";"
p = path\match "^(.-)%.lua$"
if p then insert moonpaths, p..".moon"
moonpaths = for path in *split package_path, ";"
prefix = path\match "^(.-)%.lua$"
continue unless prefix
prefix .. ".moon"
concat moonpaths, ";"
to_lua = (text, options={}) ->
@ -103,6 +103,6 @@ remove_loader = ->
{
_NAME: "moonscript"
:insert_loader, :remove_loader, :to_lua, :moon_loader, :dirsep,
:dofile, :loadfile, :loadstring
:dofile, :loadfile, :loadstring, :create_moonpath
}

View File

@ -0,0 +1,8 @@
-- moonscript module
describe "moonscript.base", ->
it "should create moonpath", ->
path = ";./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib/lua/5.1/?.luac;/home/leafo/.luarocks/lua/5.1/?.lua"
import create_moonpath from require "moonscript.base"
assert.same "./?.moon;/usr/share/lua/5.1/?.moon;/usr/share/lua/5.1/?/init.moon;/home/leafo/.luarocks/lua/5.1/?.moon", create_moonpath(path)