mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
moonlib updates, built and added to rockspec
This commit is contained in:
parent
ee5d9eaf73
commit
74060bccae
@ -1,16 +1,14 @@
|
|||||||
if not moon or not moon.inject then
|
if not moon or not moon.inject then
|
||||||
print("wrapping")
|
|
||||||
module("moon", package.seeall)
|
module("moon", package.seeall)
|
||||||
end
|
end
|
||||||
local util = require("moonscript.util")
|
local util = require("moonscript.util")
|
||||||
dump = util.dump
|
dump = util.dump
|
||||||
run_with_scope = function(fn, scope)
|
run_with_scope = function(fn, scope, ...)
|
||||||
local old_env = getfenv(fn)
|
local old_env = getfenv(fn)
|
||||||
local env = setmetatable({ }, {
|
local env = setmetatable({ }, {
|
||||||
__index = function(self, name)
|
__index = function(self, name)
|
||||||
print("indexing ", name)
|
|
||||||
local val = scope[name]
|
local val = scope[name]
|
||||||
if val then
|
if val ~= nil then
|
||||||
return val
|
return val
|
||||||
else
|
else
|
||||||
return old_env[name]
|
return old_env[name]
|
||||||
@ -18,9 +16,9 @@ run_with_scope = function(fn, scope)
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
setfenv(fn, env)
|
setfenv(fn, env)
|
||||||
return fn()
|
return fn(...)
|
||||||
end
|
end
|
||||||
bound_methods = function(obj)
|
bind_methods = function(obj)
|
||||||
return setmetatable({ }, {
|
return setmetatable({ }, {
|
||||||
__index = function(self, name)
|
__index = function(self, name)
|
||||||
local val = obj[name]
|
local val = obj[name]
|
||||||
@ -37,3 +35,70 @@ bound_methods = function(obj)
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
defaultbl = function(t, fn)
|
||||||
|
if not fn then
|
||||||
|
fn = t
|
||||||
|
t = { }
|
||||||
|
end
|
||||||
|
return setmetatable(t, {
|
||||||
|
__index = function(self, name)
|
||||||
|
local val = fn(self, name)
|
||||||
|
rawset(self, name, val)
|
||||||
|
return val
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
extend = function(...)
|
||||||
|
local tbls = {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
if #tbls < 2 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for i = 1, #tbls - 1 do
|
||||||
|
local a = tbls[i]
|
||||||
|
local b = tbls[i + 1]
|
||||||
|
setmetatable(a, {
|
||||||
|
__index = b
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return tbls[1]
|
||||||
|
end
|
||||||
|
copy = function(self)
|
||||||
|
local t = { }
|
||||||
|
for key, val in pairs(self) do
|
||||||
|
t[key] = val
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
mixin = function(self, cls, ...)
|
||||||
|
local meta = getmetatable(cls)
|
||||||
|
for key, val in pairs(meta.__index) do
|
||||||
|
if not key:match("^__") then
|
||||||
|
self[key] = val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return cls.__init(self, ...)
|
||||||
|
end
|
||||||
|
mixin_object = function(self, object, methods)
|
||||||
|
local _list_0 = methods
|
||||||
|
for _index_0 = 1, #_list_0 do
|
||||||
|
local name = _list_0[_index_0]
|
||||||
|
self[name] = function(parent, ...)
|
||||||
|
return object[name](object, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
mixin_table = function(self, tbl, keys)
|
||||||
|
if keys then
|
||||||
|
local _list_0 = keys
|
||||||
|
for _index_0 = 1, #_list_0 do
|
||||||
|
local key = _list_0[_index_0]
|
||||||
|
self[key] = tbl[key]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for key, val in pairs(tbl) do
|
||||||
|
self[key] = val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -13,7 +13,6 @@ run_with_scope = (fn, scope, ...) ->
|
|||||||
old_env = getfenv fn
|
old_env = getfenv fn
|
||||||
env = setmetatable {}, {
|
env = setmetatable {}, {
|
||||||
__index: (name) =>
|
__index: (name) =>
|
||||||
print "indexing ", name
|
|
||||||
val = scope[name]
|
val = scope[name]
|
||||||
if val != nil
|
if val != nil
|
||||||
val
|
val
|
||||||
@ -24,7 +23,7 @@ run_with_scope = (fn, scope, ...) ->
|
|||||||
fn ...
|
fn ...
|
||||||
|
|
||||||
-- wrap obj such that calls to methods do not need a reference to self
|
-- wrap obj such that calls to methods do not need a reference to self
|
||||||
bound_methods = (obj) ->
|
bind_methods = (obj) ->
|
||||||
setmetatable {}, {
|
setmetatable {}, {
|
||||||
__index: (name) =>
|
__index: (name) =>
|
||||||
val = obj[name]
|
val = obj[name]
|
||||||
@ -51,9 +50,18 @@ defaultbl = (t, fn) ->
|
|||||||
val
|
val
|
||||||
}
|
}
|
||||||
|
|
||||||
-- helper function to set metatable with index
|
-- chain together tables by __index metatables
|
||||||
extend = (base) =>
|
extend = (...) ->
|
||||||
setmetatable self, __index: base
|
tbls = {...}
|
||||||
|
return if #tbls < 2
|
||||||
|
|
||||||
|
for i = 1, #tbls - 1
|
||||||
|
a = tbls[i]
|
||||||
|
b = tbls[i + 1]
|
||||||
|
|
||||||
|
setmetatable a, __index: b
|
||||||
|
|
||||||
|
tbls[1]
|
||||||
|
|
||||||
-- shallow copy
|
-- shallow copy
|
||||||
copy = =>
|
copy = =>
|
||||||
|
@ -6,7 +6,7 @@ source = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
description = {
|
description = {
|
||||||
summary = "A little language that compiles to Lua",
|
summary = "A programmer friendly language that compiles to Lua",
|
||||||
homepage = "http://moonscript.org",
|
homepage = "http://moonscript.org",
|
||||||
maintainer = "Leaf Corcoran <leafot@gmail.com>",
|
maintainer = "Leaf Corcoran <leafot@gmail.com>",
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -35,6 +35,8 @@ build = {
|
|||||||
["moonscript.util"] = "moonscript/util.lua",
|
["moonscript.util"] = "moonscript/util.lua",
|
||||||
["moonscript.errors"] = "moonscript/errors.lua",
|
["moonscript.errors"] = "moonscript/errors.lua",
|
||||||
["moonscript.version"] = "moonscript/version.lua",
|
["moonscript.version"] = "moonscript/version.lua",
|
||||||
|
["moon"] = "moon/init.lua",
|
||||||
|
["moon.all"] = "moon/all.lua",
|
||||||
},
|
},
|
||||||
install = {
|
install = {
|
||||||
bin = { "bin/moon", "bin/moonc" }
|
bin = { "bin/moon", "bin/moonc" }
|
||||||
|
Loading…
Reference in New Issue
Block a user