Creating chainable functions that manipulate strings
#2
Try this:
PluginMsg = {}

function PluginMsg:new(a_Channel)
	local obj = {}
	setmetatable(obj, PluginMsg)
	self.__index = self
	
	obj.Channel = a_Channel
	obj.Msg = ""
	
	return obj
end

function PluginMsg:WriteUTF(a_In)
	assert(type(a_In) == "string", "Not a string!")
	local len = a_In:len()
	self.Msg = self.Msg .. string.char((len-127)/256,len % 256) .. a_In
	
	return self
end


function PluginMsg:Get()
	return self.Channel, self.Msg
end


-- How to use:
local Obj = PluginMsg:new("BungeeCord")
:WriteUTF("Connect")
:WriteUTF("MyAmazingServer")

Player:GetClientHandle():SendPluginMessage(Obj:Get())

Now, I haven't tested this, so it might not even load.
Reply
Thanks given by:


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



Users browsing this thread: 3 Guest(s)