From 0ccd5e3ca4addb1c722aa3833b27d070808d5bf9 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Mon, 16 Mar 2015 23:54:33 -0700 Subject: [PATCH] restore argument, make more moonscripty, add spec #176 --- moonscript/base.lua | 33 +++++++++++++++++++++++++-------- moonscript/base.moon | 10 +++++----- spec/moonscript_spec.moon | 8 ++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 spec/moonscript_spec.moon diff --git a/moonscript/base.lua b/moonscript/base.lua index 379b6bc..e436678 100644 --- a/moonscript/base.lua +++ b/moonscript/base.lua @@ -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 } diff --git a/moonscript/base.moon b/moonscript/base.moon index 8cfbfb3..b2068f0 100644 --- a/moonscript/base.moon +++ b/moonscript/base.moon @@ -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 } diff --git a/spec/moonscript_spec.moon b/spec/moonscript_spec.moon new file mode 100644 index 0000000..8db5558 --- /dev/null +++ b/spec/moonscript_spec.moon @@ -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) +