1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Stdlib: add string!len, table!concat, _%_

This commit is contained in:
Étienne Fildadut 2022-01-16 00:16:06 +01:00
parent 6a5595ca04
commit c4fb2649c2

View file

@ -42,6 +42,7 @@ lua_functions = {
["_*_(a::number, b::number)"] = function(a, b) return a * b end, ["_*_(a::number, b::number)"] = function(a, b) return a * b end,
["_/_(a::number, b::number)"] = function(a, b) return a / b end, ["_/_(a::number, b::number)"] = function(a, b) return a / b end,
["_//_(a::number, b::number)"] = function(a, b) return math.floor(a / b) end, ["_//_(a::number, b::number)"] = function(a, b) return math.floor(a / b) end,
["_%_(a::number, b::number)"] = function(a, b) return a % b end,
["_^_(a::number, b::number)"] = function(a, b) return a ^ b end, ["_^_(a::number, b::number)"] = function(a, b) return a ^ b end,
-- boolean -- boolean
["!_(a)"] = { ["!_(a)"] = {
@ -280,6 +281,10 @@ lua_functions = {
return { type = "number", value = 0 } return { type = "number", value = 0 }
end end
}, },
-- string
["len(s::string)"] = function(s)
return require("utf8").len(s)
end,
-- other methods -- other methods
["error(m::string)"] = function(m) error(m, 0) end, ["error(m::string)"] = function(m) error(m, 0) end,
["rand()"] = function() return math.random() end, ["rand()"] = function() return math.random() end,
@ -333,6 +338,15 @@ $ cycle(l...)
:j = 1 :j = 1
~? j += 1; j <= len(l) & !((f := l(j); 1) ~ l(j).👁 < f.👁) ~? j += 1; j <= len(l) & !((f := l(j); 1) ~ l(j).👁 < f.👁)
~ f! ~ f!
$ concat(l::list, separator=""::string)
:r = ""
:j = 0
~? j += 1; j <= len(l)
~ r += "{l(j)}"
~ j < len(l)
~ r += separator
@r
]] ]]
local functions = { local functions = {