• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

New lua engine. Is it worrth implementing that?

tarjei

Necronian Engineer
Joined
May 25, 2008
Messages
505
Reaction score
126
Location
Poland
Hello Otlanders, it's been a while since I was active here, but what is a point of this thread? To make some discussion about new lua engine and if its worth of implementing. I am sure that all of you already have heard about OTClient. I got amazed with it's own lua engine that can be mixed with tfs one.
Making some experiments with it. I didnt want to include new lua engine only so all my scripts are not working. So I took what I wanted and left behind all old stuff so none script requires changing and new stuff works aswell.

I will bring you a litle example, why I decided to make such a step.
It allowed me to easily bind sending and receiving packets. OTC lua engine allows to bind each class when its base is LuaObject.
All I did is simply binded the Player class, and make it call lua field that I define for it.
Simple as that.

Lua:
PacketHandler = {}
function PacketHandler:new() 
		local obj = {}
		obj.opcodes = {}
		self.__index = self
		setmetatable(obj, self)
		return obj
end
function PacketHandler:registerOpcode(opcode, callback)
	if callback == nil then
	    error("No callback set in registerOpcode function.")
	end
	
	if self.opcodes[opcode] == nil then
		self.opcodes[opcode] = {}
		self.opcodes[opcode].callback = callback
	else
	   error("Opcode has been already registred.")
	end
end
function PacketHandler:handle(opcode, message)
		if self.opcodes[opcode] ~= nil then
			return self.opcodes[opcode].callback(message)
		end

		return false
end
function PacketHandler:send(cid,packet)
	if (isNumber(cid) and isPlayer(cid)) then
		local player = g_game.getPlayer(cid)
		player:send(packet)
		return true
	end
	if player ~= nil then
	    local player = cid
	    player:sendPacket(packet)
	    return true
	end
	
end

And here in on login lua I set function to be called when player receive packet.

Lua:
        local player = g_game.getPlayer(cid)
	player.onRecv = function(player, opcode, message)
			return g_protocol:handle(opcode,message)
	end

Message is also instance of some class that holds buffer with data. Also binded.

I am aware that its possible to be done with tfs lua engine, but honestly.. this one is sucky: P
Prolly this is not most efficient way of handling stuff, but maybe its time to consider a litle update for tfs?
I belive it wont hurt anyone if you mean updating scripts, and it brings realy A LOT of progress.
So is it worth trying? In my opinion? FU*K YES!

Also I wanted to give BIG thanks to OTC Team. I belive that TFS team could take some fresh air for deprecated stuff in engine. (no offence)
Regards,
Tarjei
 
Meh, since I started on some fresh page of etopia I took time to completly implent the new lua engine. Positivly surprised.
 
Seems nice bro :) I agree as well.. We should start moving forward with tfs' engine.
 
Back
Top