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
|
require "lib/metaprogramming.nom"
# Moonscript!
macro block [moonscript block %moonscript_code] =:
lua block ".."
|local parse, compile = require('moonscript.parse'), require('moonscript.compile')
|local moon_code = nomsu:tree_to_value(vars.moonscript_code, vars)
|local tree, err = parse.string(moon_code)
|if not tree then
| nomsu:error("Failed to parse moonscript: "..err)
|end
|local lua_code, err, pos = compile.tree(tree)
|if not lua_code then
| nomsu:error(compile.format_error(err, pos, moon_code))
|end
|return "do\\n"..lua_code.."\\nend"
macro [moonscript %moonscript_code] =:
lua block ".."
|local parse, compile = require('moonscript.parse'), require('moonscript.compile')
|local moon_code = nomsu:tree_to_value(vars.moonscript_code, vars)
|local tree, err = parse.string(moon_code)
|if not tree then
| nomsu:error("Failed to parse moonscript: "..err)
|end
|local lua_code, err, pos = compile.tree(tree)
|if not lua_code then
| nomsu:error(compile.format_error(err, pos, moon_code))
|end
|return "(function(nomsu, vars)\\n"..lua_code.."\\nend)(nomsu, vars)"
|