Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ New feature in version 4.55 - extended CallPlugin syntax
New feature in version 4.55 - extended CallPlugin syntax
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2 3
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #15 on Wed 28 Jul 2010 06:23 AM (UTC) |
Message
| Factor out the table...
local process_results(code, arg1, ...)
if code ~= 0 then
return error(arg1, 2)
end
return arg1, ...
end
function ImportPlugin(id, name)
return function(...)
return process_results(CallPlugin(...))
end
end
Foo = ImportPlugin("80cc18937a2aca27079567f0", "Foo")
Foo("Hello, world!")
No messing directly with tables. I like this code! |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #16 on Wed 28 Jul 2010 06:24 AM (UTC) |
Message
|
Nick Gammon said:
Twisol said:
Ah, right. Well then:
...
local results = {assert(orig(...))}
...
You gotta lose the assert. The first return value is never nil, nor false.
Yeah, I accidentally forgot to remove it. ^_^; |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #17 on Wed 28 Jul 2010 06:26 AM (UTC) Amended on Wed 28 Jul 2010 06:27 AM (UTC) by Nick Gammon
|
Message
| Yes, that is getting there. Even this:
function ImportPlugin(id, name)
_G [name] = function(...)
return process_results(CallPlugin(...))
end
end
ImportPlugin("80cc18937a2aca27079567f0", "Foo")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #18 on Wed 28 Jul 2010 06:28 AM (UTC) |
Message
| Er:
function ImportPlugin(id, name)
_G [name] = function(...)
return process_results(CallPlugin(id, name, ...))
end
end
ImportPlugin("80cc18937a2aca27079567f0", "Foo")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #19 on Wed 28 Jul 2010 06:29 AM (UTC) |
Message
|
Nick Gammon said:
Worstje said:
How difficult would it be to support Lua -> Non-Lua calls?
Once defined, the prototype for a OLE function is not supposed to change. So I can't change it from returning a long to returning a table. Or accepting a table instead of a string.
Maybe CallPluginEx could be defined in a different way. Maybe we encourage everyone to use Lua.
As I said, you don't *have* to use the new method. The old one survived for quite a few years. And you have Twisol's language-neutral PPI as a fallback.
I don't see how the prototype would change. There would be two ways to deal with it...
# Python
def MyFunc(a, b, c):
pass
... could only be called with 3 parameters. If more or less are used, it would be valid to throw an error.
Alternatively...
# Python
def MyFunc(params)
a, b, c, d = params # unpack the values
pass
... should work just fine. On WSH level, one would probably use an array-like object as being the 'params' in question. This way, there would be no need to worry about any signatures changing. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #20 on Wed 28 Jul 2010 06:42 AM (UTC) |
Message
| It's not just the number of arguments, it's the type.
I could get away with it in Lua, because it isn't constrained by the rules for OLE objects. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #21 on Wed 28 Jul 2010 06:48 AM (UTC) |
Message
| I'm familiar with the types used in OLE / COM stuff, although it's been a few years. I am pretty sure there are ways to return non-ints, such as an array which, once more, could contain the multiple return values. E.g.
# Python, skipping the obvious type checks for clarity
def MyFunc(params):
a, b, c, d = params
return [a + b, c + d]
Perhaps it takes an out-declared parameter to return non-ints (I doubt that tho). I don't recall the specifics, but I am about 99% certain the concept I am talking about is possible. | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #22 on Wed 28 Jul 2010 06:57 AM (UTC) |
Message
|
Nick Gammon said:
Er:
function ImportPlugin(id, name)
_G [name] = function(...)
return process_results(CallPlugin(id, name, ...))
end
end
ImportPlugin("80cc18937a2aca27079567f0", "Foo")
I'm not a fan of forcing the user to use a global in general, so I prefer actually returning the value and letting them set it as they wish. It's not really that much more typing, and you can create a wrapper around ImportPlugin to do it if you must. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| WillFa
USA (525 posts) Bio
|
Date
| Reply #23 on Wed 28 Jul 2010 07:03 AM (UTC) Amended on Wed 28 Jul 2010 07:04 AM (UTC) by WillFa
|
Message
| I actually agree as well... plus, if my calling plugin has a Foo function, I don't want to trample it because I don't have the option of using "otherFoo = ImportPlugin()"
Slightly different question... I don't remember how you changed dependency loading... Does PluginA parse, PluginA calls OnPluginInstall(), PluginB parses... or do they all parse first before executing OnPluginInstall (so if a plugin does a broadcast in its install, dependent plugins have a chance to catch it) | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #24 on Wed 28 Jul 2010 07:14 AM (UTC) |
Message
| He didn't change it, it still parses and runs OnPluginInstall at the same time. OnPluginListChanged was added as a mitigating factor. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #25 on Wed 28 Jul 2010 07:17 AM (UTC) |
Message
|
Worstje said:
I'm familiar with the types used in OLE / COM stuff, although it's been a few years. I am pretty sure there are ways to return non-ints, such as an array which, once more, could contain the multiple return values.
You can do all that, you just are not supposed to change the interfaces to a COM object, once it has been released. So I can't make something that used to take a string argument today, take a table argument tomorrow. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #26 on Wed 28 Jul 2010 07:20 AM (UTC) |
Message
| You could create a new function CallPluginEx. :) |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #27 on Wed 28 Jul 2010 07:36 AM (UTC) |
Message
| I did say CallPluginEx from my very first post where I suggested it, didn't I?
I need to find the bold button so people actually read my blurbs, I bet. First Twisol and now you, I feel like an old record. =) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #28 on Wed 28 Jul 2010 07:59 AM (UTC) |
Message
| That *was* Twisol. However you did indeed mention it in your first post. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #29 on Wed 28 Jul 2010 08:04 AM (UTC) Amended on Wed 28 Jul 2010 08:05 AM (UTC) by Twisol
|
Message
| Hmm, I don't remember suggesting CallPluginEx before now. My claim to fame in this thread is the ImportPlugin wrapper. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
87,183 views.
This is page 2, subject is 3 pages long:
1
2 3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top