Page 1 of 1

[Feature Request] SysDataUserCommandRequestEvent

Posted: Sun Aug 12, 2012 4:54 pm
by Avaloniac
hey, for a command queue i need do differ send requests from user command and send(), so a user command event would be nice, or a way to bypass SysDataSendRequest.

regards, Avaloniac.

Re: [Feature Request] SysDataUserCommandRequestEvent

Posted: Tue Aug 14, 2012 12:15 am
by Widjet
Could you not override the send function so that it toggled a flag for use with SysDataSendRequest?
eg:
Code: [show] | [select all] lua
function newSend(cmd)
  this_is_send_command = true
  send(cmd)
end

function onSysDataSendRequest()
  if this_is_send_command then
    --Send command.
  else
    --User command.
  end
  this_is_send_command = false
end
Putting in another event is of course possible, but you can work around the lack, can't you? You could also work around it by having an alias (.+) that captures anything that the user tries to send.

Or am I misinterpreting your request?

Re: [Feature Request] SysDataUserCommandRequestEvent

Posted: Tue Aug 14, 2012 3:30 am
by Oneymus
I believe the new function suggestion is the best way to go. If you want to overwrite the current send, I would recommend this method:
Code: [show] | [select all] lua
do
  oldSend = send
  function send (what)
    send_flag = true
    oldSend( what )
  end
end

Re: [Feature Request] SysDataUserCommandRequestEvent

Posted: Tue Aug 14, 2012 3:37 am
by Widjet
One addendum to Oneymus' code though - make sure you don't run that code twice! Every time you run that code, you're wrapping send in an additional function, which will slow things down.

Also, send() can take a second parameter, so you might want to pass that through as well (if you ever want to do hidden sends).

Re: [Feature Request] SysDataUserCommandRequestEvent

Posted: Tue Aug 14, 2012 3:46 am
by Vadi
... and all in all, be careful when tinkering with send(), a lot of scripts use that so if you mess it up, things can break (until you restart Mudlet anyway). This is one feature in Lua that's extremely powerful but you want to have some knowledge when fiddling with it ;)