Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
06-06-2012, 10:44 PM
Oh my God! - that was first thought I had when I found GetLuaPlugin(). In the Bindings. So, it's a function, seems like it should return Lua Plugin instance (looked into source: a-ha! it does!), and it's exported to Lua. Brilliant!
"Hold on, boy, look what this function needs as arguments..."
Damn! Some lua_State pointer, and I HAVE NO IDEA (remembered Meet Medic from TF2... nevermind) what that thing is...
FakeTruth, I need your torch there!
(because the idea of grabbing plugin instance in another plugin seems to be VERY desired by me)
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
lua_State is automagically passed when you call a function from Lua. Or something like that..
But even if you did get a plugin reference, you still can't call Lua functions on it ( you can call the c++ functions, but why would you )
All plugins have their own 'sandboxed' lua_State (own stack, memory, etc.) which means they cannot interact with each other in a normal fashion.
I don't think you can easily forward Lua functions with any number of arguments/return values called from one state to the other.
The easiest way is to add a generic function to plugins that accepts a string and returns a string
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Like I said, a generic string function can be added which can be called on plugins by other plugins, but it's hardly ideal
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
In Lua a string is a number and/or string, it converts automagically. So it's pretty much the same as your IniFile idea
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
I guess with the separate lua_state we have effectively sandboxed each plugin and it's now quite impossible for two of them to communicate directly. I, however, think that it should be possible to pass simple "messages" between them, somewhat like Windows' PostMessage() and maybe even SendMessage().
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Yeah, sending messages is totally possible, because you can queue them and handle them in the tick function or something. But that means you cannot immediately get a value back