Page 1 of 1

Suggest atExit return previous callback

Posted: Wed Apr 10, 2013 1:02 pm
by dx876234
I suggest the atExit() function is modified to return the old callback, this should be done in all callback function. This would enable chaining.

-dx

Code: Select all

function atExit(func)
	if( type(func) ~= "function" and type(func) ~= "nil" ) then
		local err = "Error: Non-function type passed to atExit() where a function is expected.";
		setTextColor(cli.yellow);
		error(err, 2);
		return;
	end

	local ofunc = __EXIT_CALLBACK
	__EXIT_CALLBACK = func;
	return ofunc
end

Re: Suggest atExit return previous callback

Posted: Thu Apr 11, 2013 10:51 am
by Administrator
I'm not sure if I agree with this. The default callback just prints a line of text and that's it; there would really be no reason to need to 'chain' it. Rather than setting multiple callbacks in your code, you should combine them into one. You could also just use function hooking to accomplish the same thing.

Re: Suggest atExit return previous callback

Posted: Fri Apr 12, 2013 6:57 am
by dx876234
My specific issue is that rombot uses atexit internally:

Code: Select all

function exitCallback()
	releaseKeys();
end
atExit(exitCallback);
I would like to hook onto it as well in my script but would prefer not to be dependent on the internals of the bot. But its not a biggie, I can call the exitCallback() from my own callback.

-dx

Re: Suggest atExit return previous callback

Posted: Fri Apr 12, 2013 2:34 pm
by Administrator
A hook would work, but you can also just do this:

Code: Select all

function my_exitCallback()
  exitCallback();
  -- Any additional code here
end
atExit(my_exitCallback);

Re: Suggest atExit return previous callback

Posted: Mon Apr 15, 2013 6:43 am
by dx876234
Ye, thats what I'm doing atm, problem is that this is a userfunction so what happens if another userfunction also needs to handle the exit or pause callback? Or a user uses it in his/her waypoint script? It would be nice to be able to subscribe to these events without having to hardcode.

Just my 5 cents :)

-dx

Re: Suggest atExit return previous callback

Posted: Mon Apr 15, 2013 7:46 am
by lisa
I use this in a userfunction.

Code: Select all

function logtrace()
	errorCallback()
	logInfo(player.Name,debug.traceback(),true,"crashes")
end
atError(logtrace)

Re: Suggest atExit return previous callback

Posted: Mon Apr 15, 2013 8:27 am
by dx876234
I also use the atError in an userfunction Lisa, I havent noticed any collitions yet but theyr there...

-dx

Re: Suggest atExit return previous callback

Posted: Mon Apr 15, 2013 4:52 pm
by Administrator
Really, that is something that should be handled by the main script. It would be best to register it as an event and have the script call it as the user requests.

What are you attempting to accomplish with the atExit() callback?

Re: Suggest atExit return previous callback

Posted: Wed Apr 17, 2013 6:30 am
by dx876234
I see your point, this prolly should be a task for the executing script.

I've started an Event Manager as an userfunction and will publish in rom userfunction section shortly. It will take over all event exits in MM and enable subscription of these, for compatibility w RoMBot I'm registering all its original callbacks as subscribed on their respective events. The userfunction also enables user defined events for other waypoints/userfunctions to define and subscribe to, as example I'm using player detection and mob detection.

best regard
DX

Re: Suggest atExit return previous callback

Posted: Wed Apr 17, 2013 11:00 am
by Administrator
I think that's an excellent idea. When we were working on some scripts for GW2, we had a very clean, event-based system. You might be able to use some of it, or at least get some ideas.
https://code.google.com/p/gw2-bot/source/list