This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
NamelessKonata's profile picture

A problem with a call for an existing function.

Started by NamelessKonata, 20 June 2013 - 11:15 AM
NamelessKonata #1
Posted 20 June 2013 - 01:15 PM
Hello everyone. I've got a small problem. An error, that crashes LUA, pointing towards the function non-existence.
But there IS a function, and it loads before it is called. Here is the code, for everything else go to PM


function string:split(sep)
	    local sep, fields = sep or ":", {}
	    local pattern = string.format("([^%s]+)", sep)
	    self:gsub(pattern, function(c) fields[#fields+1] = c end)
	    return fields
end

If, for example, I use:
lua tbl = msg:split(":")
Then there's an error "attempt to call nill"

Thanks in advance.
Edited by
Lyqyd #2
Posted 20 June 2013 - 01:46 PM
Split into new topic.

Try declaring it thus instead:

string.split = function(self, sep)
NamelessKonata #3
Posted 20 June 2013 - 01:59 PM
Split into new topic.

Try declaring it thus instead:

string.split = function(self, sep)
When in use it doesn't work. Plus it's strange. It was all working until today. It just stopped seeing the function.
Lyqyd #4
Posted 20 June 2013 - 02:14 PM
"Doesn't work" in what way? You should probably post the rest of the code.
ElvishJerricco #5
Posted 20 June 2013 - 02:18 PM
Unfortunately a string doesn't reference the string library the way we wish it would. If you add a function to the string library, it doesn't get added to normal strings. You'll have to do string.split(str, "sep") instead of str:split("sep")
NamelessKonata #6
Posted 21 June 2013 - 08:04 AM
I've changed the code a bit, and I could use the Luqyd's method. But it's strange. The function perfectly worked before. The problem is solved, thanks.