A look at the latest cSlave's scripting API
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

A look at the latest cSlave's scripting API

Started by Corayzon, 13 August, 2004, 11:13:41

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Corayzon

here is a little snipet from cslaves API file events.lua

-- Event API for cSlave 1.0
-- Writin by Corayzon (Matty D)
-- Once fully tested remove this line

tPtokaxEvents = 
{
	-- pTokax Functions
	["Main"] = {},
	["DataArrival"] = {},
	["NewUserConnected"] = {},
	["OpConnected"] = {},
	["OpDisconnected"] = {},
	["UserDisconnected"] = {},
}

tProtocol = 
{
	-- P2P Protocol
	["$MyNick"] = {},
	["$Key"] = {},
	["$ValidateNick"] = {},
	["$MyPass"] = {},
	["$Version"] = {},
	["$GetNickList"] = {},
	["$MyINFO"] = {},
	["$GetINFO"] = {},
	["$ConnectToMe"] = {},
	["$MultiConnectToMe"] = {},
	["$RevConnectToMe"] = {},
	["$Search"] = {},
	["$MultiSearch"] = {},
	["$SR"] = {},
	["$To:"] = {},
	["$Kick"] = {},
	["$OpForceMove"] = {},
	["$Quit"] = {},
	["<"] = {},

	-- cSlave Addon Protocol
	["$MyIP"] = {},
	["$Bot"] = {},

	-- Other Protocol Support
	["Other"] = {}
}

function doPtokaxEvent(sEvent, vArg1, vArg2)
	local iReturn
	if tPtokaxEvents[sEvent] then
		for sFuncName, fFunction in tPtokaxEvents[sEvent] do
			if iReturn == nil then
				iReturn = fFunction(vArg1 or nil, vArg2 or nil)
			else
				fFunction(vArg1 or nil, vArg2 or nil)
			end
		end
		return iReturn
	end
end

function doProtocolEvent(sEvent, vArg1, vArg2)
	local iReturn
	if type(tProtocol[sEvent]) == "table" then
		for sFuncName, fFunction in tProtocol[sEvent] do
			if iReturn == nil then
				iReturn = fFunction(vArg1 or nil, vArg2 or nil)
			else
				fFunction(vArg1 or nil, vArg2 or nil)
			end
		end
		return iReturn
	end
end

function regPtokaxEvent(sEvent, fFunction)
	assert(type(sEvent) == "string", "regPtokaxEvent(sEvent, fFunction) - sEvent must be a string!")
	assert(type(fFunction) == "function", "regPtokaxEvent(sEvent, fFunction) - fFunction must be a function!")
	if not tPtokaxEvents[sEvent] then
		return 1, sEvent .. " was not found!"
	end
	tPtokaxEvents[sEvent][tostring(fFunction)] = fFunction
end

function regProtocolEvent(sEvent, fFunction)
	assert(type(sEvent) == "string", "regProtocolEvent(sEvent, fFunction) - sEvent must be a string!")
	assert(type(fFunction) == "function", "regProtocolEvent(sEvent, fFunction) - fFunction must be a function!")
	if not tProtocol[sEvent] then
		return 1, sEvent .. " was not found!"
	end
	tProtocol[sEvent][tostring(fFunction)] = fFunction
end

noza

NightLitch

Looks nice, how do u execute the tPtokaxEvents ??

I mean the script depends in those:

function Main()
end

etc.

Nice btw.

/NL
//NL

Corayzon

the tPtokaxEvents executes the stored functions in the table when doPtokaxEvent(sEvent) is called, ...

it is used by the cSlave addons system so that the addon files may have function Main() and so on while not overwriting the main cslave script.

and it also has a regPtokaxEvent(sEvent, fFunction) so u can dependly pass the ptokax functions to ur own scripts.

*** This is nice, but there is much more to be prode of about the new cslave, but u guys will just have to wait!

and btw, the new cslave is designed for ppl to write scripts in the API. It can execute multiple scripts in a similar fasion to ptokax while keeping all the globals shared (think of what can be done, and without hugh cluttered script files!). And it is also able to execute any script for ptokax within itself so that script passing works correctly. (when one script returns 1, the other scripts inline dont execute!)

and u can even run it with  robo!

enough blabber!

noza

Corayzon

This is a snipet from cSlaves startup script.

This executes the scripts in the addons\scripts dir and makes references to the main ptokax functions and stores them into the tPtokaxEvents before loading the next. When its done it reloads the main cslave functions to pointers saved from startup.

function ExecuteAddonScripts()
	execute("dir \"cSlave Addons\\Scripts\\*.lua\" /b > \"cSlave System\\Data\\Directory Dumps\\Addons\\Scripts.dir\"")
	readfrom("cSlave System/Data/Directory Dumps/Addons/Scripts.dir")
	local sLine = read()
	while sLine ~= nil do
		SendToAll("*** found " .. sLine .. ". Extension = " .. strsub(sLine, strlen(sLine) - 3, strlen(sLine)))
		if strsub(sLine, strlen(sLine) - 3, strlen(sLine)) == ".lua" then
			ClearCslavePtokaxFunctions()
			SendToAll("*** executing " .. sLine)
			assert(dofile("cSlave Addons/Scripts/" .. sLine), "Error traceback :- " .. sLine .. "!")
			if type(Main) == "function" then
				tPtokaxEvents["Main"][sLine] = Main
			end
			if type(DataArrival) == "function" then
				tPtokaxEvents["DataArrival"][sLine] = DataArrival
			end
			if type(NewUserConnected) == "function" then
				tPtokaxEvents["NewUserConnected"][sLine] = NewUserConnected
			end
			if type(OpConnected) == "function" then
				tPtokaxEvents["OpConnected"][sLine] = OpConnected
			end
			if type(UserDisconnected) == "function" then
				tPtokaxEvents["UserDisconnected"][sLine] = UserDisconnected
			end
			if type(OpDisconnected) == "function" then
				tPtokaxEvents["OpDisconnected"][sLine] = OpDisconnected
			end
		end
		sLine = read()
	end
	RestoreCslavePtokaxFunctions()
	readfrom()
end

noza

NightLitch

Looks nice, I must say I understand some and some not hehe...

Keep ut the good work.

Regards / NL
//NL

Corayzon

ill be takin that as a complement :rolleyes:

noza

SMF spam blocked by CleanTalk