Some LUA functions are not working as expected

@nick the LUA code for string.gmatch() doesn’t seem to work. I had to hard code an alternate string splitting method.

Is there a quick way to check which string and other methods are currently supported for LUA?

I would like to use something like the following from this guide:

local example = "an example string"
for i in string.gmatch(example, "%S+") do
  print(i)
end

Here are the rest of the string functions from this guide:

Working:

string.byte(s [, i [, j]])
string.char(i1, i2, ...)
string.len(s)
string.lower(s)
string.upper(s)
string.reverse(s)
string.sub(s, i [, j])

Not working as expected

string.dump(function)
string.find(s, pattern [, index [, plain]])
string.format(s, e1, e2, ...)
string.gmatch(s, pattern)
string.gsub(s, pattern, replace [, n])
string.match (s, pattern [, index])
string.rep(s, n)

 

Test code utilized:

local theFunction = function()
    return "Not the string you wanted"
end

local theString = "This is a string"

hero:say(string.byte("ABCDE") .. " - byte")
hero:say(string.char(65,66,67) .. " - char")
hero:say(string.upper(theString) .. " - upper")
hero:say(string.lower(theString) .. " - lower")
hero:say(string.len(theString) .. " - len")
hero:say(string.reverse(theString) .. " - reverse")
hero.say(string.sub(theString, 6, 9) .. " - sub")

-- Not currently working
hero:say(string.rep("Lua ",5) .. " - rep")
hero:say(string.match("I have 2 questions for you.", "%d+ %a+") .. " - match")
hero.say(string.gsub("Hello banana", "banana", "Lua user") .. " - gsub" )
hero:say("Gmatching!")
for word in string.gmatch("Hello Lua user", "%a+") do hero:say(word) end
hero:say(string.format("%s %q", "Hello", "Lua user!") .. " - format")
hero:say(string.find("Hello Lua user", "Lua") .. " - find")
hero:say(string.dump(theFunction) .. " - function")
1 Like

Here is a list of math functions in LUA ( guide )

Working:

a^b
math.abs()
math.cost() math.sin() math.tan()
math.acos() math.asin() math.atan() math.atan2(x,y)
math.log() math.log10()
math.ceil()
math.floor()
math.sqrt()
math.random()
math.pow(num, exp)
-- should not work but does
math.PI

Not working as expected

math.pi
math.deg()
math.rad()
math.randomseed()
math.random(num)
math.random(low,high)

Test code utilized:

hero:say(2^4 .. " - power")
hero:say(math.pow(2,4) .. " - pow")
hero:say(math.abs(-2) + math.abs(2) .. " - abs")
hero:say("cos sin tan are all in radians. PI = " .. math.PI)
hero:say(math.cos(30) .. " - cos")
hero:say(math.acos(math.cos(30)) .. " - acos")
hero:say(math.sin(60) .. " - sin")
hero:say(math.asin(math.sin(60)) .. " - asign")
hero:say(math.tan(45) .. " - tan")
hero:say(math.atan(math.tan(45)) .. " - atan")
hero:say(math.atan2(1,-1) .. " - atan2")
hero:say(math.ceil(3.5) .. " - ceil")
hero:say(math.floor(3.5) .. " - floor")
hero:say(math.log(50) .. " - log")
hero:say(math.log10(50) .. " - log10")
hero:say(math.sqrt(2^2) .. " - sqrt")
hero:say(math.random() .. " - random")

1 Like

Ah yeah, we have a few gaps in the standard library. Here’s the list we know about:

Can you submit an issue or pull request to update the README there with anything that’s not working that’s also not listed?

2 Likes

@nick I am still working on my Git’ish. When you say submit a pull request, to me a pull is when you grab the content form the repository to local to work on. Would this be equivalent to saying submit an update to the read me? Push is what I thought you do when you are done with the code… And then would it be a push request?

[edit]

Never mind I just got the definition:

Pull requests let you tell others about changes you’ve pushed to a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before the changes are merged into the repository.

But isn’t this counter intuitive? Should they really call this a “push” request, as one can always pull right?

1 Like

Yeah, a bit confusing. It’s a request for us to pull your changes into the main repository.

1 Like