Suggest atExit return previous callback

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
dx876234
Posts: 188
Joined: Sat Jul 24, 2010 6:13 am

Suggest atExit return previous callback

#1 Post 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
User avatar
Administrator
Site Admin
Posts: 5344
Joined: Sat Jan 05, 2008 4:21 pm

Re: Suggest atExit return previous callback

#2 Post 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.
dx876234
Posts: 188
Joined: Sat Jul 24, 2010 6:13 am

Re: Suggest atExit return previous callback

#3 Post 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
User avatar
Administrator
Site Admin
Posts: 5344
Joined: Sat Jan 05, 2008 4:21 pm

Re: Suggest atExit return previous callback

#4 Post 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);
dx876234
Posts: 188
Joined: Sat Jul 24, 2010 6:13 am

Re: Suggest atExit return previous callback

#5 Post 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
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Suggest atExit return previous callback

#6 Post by lisa »

I use this in a userfunction.

Code: Select all

function logtrace()
	errorCallback()
	logInfo(player.Name,debug.traceback(),true,"crashes")
end
atError(logtrace)
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
dx876234
Posts: 188
Joined: Sat Jul 24, 2010 6:13 am

Re: Suggest atExit return previous callback

#7 Post by dx876234 »

I also use the atError in an userfunction Lisa, I havent noticed any collitions yet but theyr there...

-dx
User avatar
Administrator
Site Admin
Posts: 5344
Joined: Sat Jan 05, 2008 4:21 pm

Re: Suggest atExit return previous callback

#8 Post 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?
dx876234
Posts: 188
Joined: Sat Jul 24, 2010 6:13 am

Re: Suggest atExit return previous callback

#9 Post 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
User avatar
Administrator
Site Admin
Posts: 5344
Joined: Sat Jan 05, 2008 4:21 pm

Re: Suggest atExit return previous callback

#10 Post 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
Post Reply