Creating chainable functions that manipulate strings
#3
Aside from my copy/paste capitalizing the "o" in line 8 (wtf?), it compiled fine.

Adding this to a test file with your code:
function readUTF(a_str)
  local len, str = string.byte(a_str,1) * 256 + string.byte(a_str,2), a_str:sub(3)
  return str:sub(1,len), str:sub(len+1)
end
local obj = PluginMsg:new("Bungeecord"):WriteUTF("Test"):WriteUTF("Hi")
local channel, msg = obj:Get()
local o1, rem1 = readUTF(msg)
local o2, _ = readUTF(rem1)
print(o1 .. " " .. o2)
I got the error "{file location stuff}\testchaining.lua:31: attempt to call method 'WriteUTF' (a nil value)" where 31 is the line where I defined obj. I then tried splitting it up
local obj = PluginMsg:new("Bungeecord")
local obj2 = obj:WriteUTF("Test")
local obj3 = obj2:WriteUTF("Hi")
but it errored out (same error) on the first line with WriteUTF. I'm assuming this means that somethings going wrong in the metatable line, but I've no idea how to fix it.
Reply
Thanks given by:


Messages In This Thread
RE: Creating chainable functions that manipulate strings - by Zee1234 - 10-28-2015, 06:33 AM



Users browsing this thread: 2 Guest(s)