aboutsummaryrefslogtreecommitdiff
path: root/nomsu.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-24 13:13:03 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-24 13:13:26 -0800
commitf769351556cceed58ab6bf844c671114ec1862c2 (patch)
treedd7dcf811082cf4e4c4bb0b6b3cd3811cf4385e1 /nomsu.lua
parentd173e9ae88380bb1217b3f775e6c3cec71a6606c (diff)
Updated and improve syntax for some stuff. Also added string indexing
like in python, including slices.
Diffstat (limited to 'nomsu.lua')
-rw-r--r--nomsu.lua26
1 files changed, 22 insertions, 4 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 88ad87f..282831c 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -26,6 +26,18 @@ do
STRING_METATABLE.__add = function(self, other)
return self .. stringify(other)
end
+ STRING_METATABLE.__index = function(self, i)
+ if type(i) == 'number' then
+ return string.sub(self, i, i)
+ elseif type(i) == 'table' then
+ return string.sub(self, i[1], i[2])
+ else
+ return string[i]
+ end
+ end
+ STRING_METATABLE.__mul = function(self, other)
+ return string.rep(self, other)
+ end
end
lpeg.setmaxstack(10000)
local P, R, V, S, Cg, C, Cp, B, Cmt
@@ -1388,10 +1400,16 @@ do
}
end)
self:define_compile_action("lua> %code", "nomsu.moon", function(_code)
- local lua = nomsu_string_as_lua(_code)
- return {
- statements = lua
- }
+ if _code.type == "Text" then
+ local lua = nomsu_string_as_lua(_code)
+ return {
+ statements = lua
+ }
+ else
+ return {
+ statements = "nomsu:run_lua(" .. tostring(nomsu:tree_to_lua(_code).expr) .. ");"
+ }
+ end
end)
self:define_compile_action("=lua %code", "nomsu.moon", function(_code)
local lua = nomsu_string_as_lua(_code)