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:
parent
6a5595ca04
commit
c4fb2649c2
1 changed files with 14 additions and 0 deletions
|
|
@ -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 = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue