-
Notifications
You must be signed in to change notification settings - Fork 0
/
om
35 lines (30 loc) · 910 Bytes
/
om
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local function isFile(path)
if not fs.isDir(path) and fs.exists(path) then
return true
end
return false
end
local function loadModule(path, modulename)
assert(isFile(path), "Could not find module: " .. tostring(path))
local reader = fs.open(path, "r")
local content = reader.readAll()
reader.close()
local filefunction, err = loadstring(content)
if not filefunction then
error("Could not load module: " .. tostring(path) .. " Reason: " .. err)
end
local ret = {}
local ok, err = pcall(function() ret = filefunction() end)
if not ok then
error("Could not execute module: " .. tostring(path) .. " Reason: " .. err)
end
rawset(_G.om, modulename, ret)
end
rawset(_G, "om", {})
loadModule("om_error", "error")
loadModule("om_input", "input")
loadModule("om_lexer", "lexer")
loadModule("om_parser", "parser")
rawset(_G.om, "loadstring", function(...)
return om.parser:loadstring(...)
end)