[REQUEST] atStop
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.
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.
[REQUEST] atStop
Hi!
Is it possible to add an atStop function (similar to atExit), which would be called when the script stops by pressing the stop key?
Thanks in advance.
Is it possible to add an atStop function (similar to atExit), which would be called when the script stops by pressing the stop key?
Thanks in advance.
- Administrator
- Site Admin
- Posts: 5331
- Joined: Sat Jan 05, 2008 4:21 pm
Re: [REQUEST] atStop
Sure. I can add this. But the question is, should an exit (CTRL+L) generate the stop event, as well?
Re: [REQUEST] atStop
Good question. i think so, because stoping a script before it exits makes sense to me. Furthermore, i think that atStop would be used for cleaning or logging purposes and it doesn't affect later events.
Just my opinion.
Just my opinion.
- Administrator
- Site Admin
- Posts: 5331
- Joined: Sat Jan 05, 2008 4:21 pm
Re: [REQUEST] atStop
I've added this as well as atResume(). The updated executable is attached (just the .exe, so don't delete anything yet).
Re: [REQUEST] atStop
Hi! I tried:
But I got an error:
"...of\Desktop\mutools\micromacro\scripts\mu-engnovo.lua:399: attempt to call global 'atStop' (a nil value)".
Could you give an example? Thank you.
Code: Select all
function stop_callback()
printf("Stoping...\n");
end
atStop(stop_callback);
"...of\Desktop\mutools\micromacro\scripts\mu-engnovo.lua:399: attempt to call global 'atStop' (a nil value)".
Could you give an example? Thank you.
- Administrator
- Site Admin
- Posts: 5331
- Joined: Sat Jan 05, 2008 4:21 pm
Re: [REQUEST] atStop
The function is atPause() instead of atStop().
Re: [REQUEST] atStop
Didn't work. I tried:
But, I still got: "...of\Desktop\mutools\micromacro\scripts\atPause.lua:7: attempt to call global 'atPause' (a nil value)"
Where is my mistake?
Code: Select all
startKey = key.VK_INSERT;
stopKey = key.VK_DELETE;
function pause_callback()
printf("Pausing...\n");
end
atPause( pause_callback );
function main()
while(true) do
printf("Running...\n");
yrest(100);
end
end
startMacro(main);
Where is my mistake?
- Administrator
- Site Admin
- Posts: 5331
- Joined: Sat Jan 05, 2008 4:21 pm
Re: [REQUEST] atStop
My mistake. I forgot about the changes to lib.lua. Here's a full update that includes the atPause() and atResume() functions.
Re: [REQUEST] atStop
Both files you've uploaded are the same. Not working yet.
- Administrator
- Site Admin
- Posts: 5331
- Joined: Sat Jan 05, 2008 4:21 pm
Re: [REQUEST] atStop
I attached the wrong file again. This one should work.
Re: [REQUEST] atStop
Function yrest causes error inside the callback function... For example:
I got error: "...of\Desktop\micromacro\scripts\atPause.lua:5: attempt to yield across metamethod/C-call boundary".
Isn't it possible? Thank you.
Code: Select all
startKey = key.VK_INSERT;
stopKey = key.VK_DELETE;
function pause_callback()
yrest(100);
printf("Pausing...\n");
end
atPause( pause_callback );
function main()
while(true) do
printf("Running...\n");
yrest(100);
end
end
startMacro(main);
Isn't it possible? Thank you.
- Administrator
- Site Admin
- Posts: 5331
- Joined: Sat Jan 05, 2008 4:21 pm
Re: [REQUEST] atStop
Nice find. Well, I figured out where the problem was. The good news is that it's "fixed." The bad news is that you still won't be able to yield.
See, the callback function is being called from the main thread (is not a coroutine). Because of this, you cannot yield it. So, I added a check into safeYield() to see if it is in the main thread, and do nothing if it is. The result is that you will still be resting, but not yielding (so other threads will not actually be getting CPU time here...which is actually a good thing for these types of events).
Here's the safeYield() patch:
See, the callback function is being called from the main thread (is not a coroutine). Because of this, you cannot yield it. So, I added a check into safeYield() to see if it is in the main thread, and do nothing if it is. The result is that you will still be resting, but not yielding (so other threads will not actually be getting CPU time here...which is actually a good thing for these types of events).
Here's the safeYield() patch:
Code: Select all
-- Runs a coroutine in a protected state, if available
function safeYield()
-- make sure we're not trying to yield in the main thread
-- do nothing.
local co = coroutine.running();
if( co == nil ) then
return;
end
if( cocoAvailable ) then
local status, err = pcall(coroutine.yield);
if( status ~= true ) then
__log_traceback();
setTextColor(cli.yellow);
error(err, 3);
end
else
coroutine.yield();
end
end
Who is online
Users browsing this forum: No registered users and 2 guests