Created
August 28, 2019 23:30
-
-
Save Janfel/d4550f62ec47821e9f2cedf17a7812ab to your computer and use it in GitHub Desktop.
Sample library for a functional-ish subset of Moonscript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import to_lua from require "moonscript" | |
environment = { | |
:_VERSION | |
:tostring | |
:tonumber | |
:pairs | |
:ipairs | |
:next | |
:type | |
:unpack | |
:math | |
:table | |
:string | |
-- Metatable operations | |
--:setmetatable | |
--:getmetatable | |
--:rawset | |
--:rawget | |
--:rawlen | |
--:rawequal | |
-- Eval operations | |
--:load | |
--:loadstring | |
--:loadfile | |
--:dofile | |
-- Error handling | |
--:error | |
--:assert | |
--:pcall | |
--:xpcall | |
-- Module system | |
--:module | |
--:require | |
--:package | |
-- Outside information | |
--:_G | |
--:arg | |
--:io | |
--:os | |
-- Side effects | |
--:debug | |
--:collectgarbage | |
-- Not declarative | |
--:coroutine | |
--:select | |
} | |
-- Returns func?, err? | |
loadstring = (code, name="=(moonata \"#{code}\")", mode=nil) -> | |
luacode = assert to_lua code | |
load luacode, name, mode, environment | |
-- Returns func?, err? | |
loadfile = (fname, name="=[file #{fname}]", mode=nil) -> | |
file = assert io.open fname | |
code = assert file\read "*a" | |
loadstring code, name, mode | |
{ | |
:loadstring | |
:loadfile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment