Cuberite Forum
Global Function? - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Global Function? (/thread-38.html)



Global Function? - Dys0n - 03-01-2011

Can i make a function that can be called in all plugins eg if i make a function called

Coldsteel:SendData( pName, Message )

How could i call that in all lua scripts?


RE: Global Function? - Revolucas - 03-01-2011

(03-01-2011, 11:23 AM)Dys0n Wrote: Can i make a function that can be called in all plugins eg if i make a function called

Coldsteel:SendData( pName, Message )

How could i call that in all lua scripts?

In Lua you can use require. But I wouldn't know how to get that to work with this. I'm guessing you can't unless he implemented the use of a _G.lua script where everything inside is global. I used something similar while modifying the game S.T.A.L.K.E.R. If someone knows the right answer this would be quite helpful in the future.


RE: Global Function? - Tybor - 03-02-2011

(03-01-2011, 11:23 AM)Dys0n Wrote: Can i make a function that can be called in all plugins eg if i make a function called

Coldsteel:SendData( pName, Message )

How could i call that in all lua scripts?

Haven't tried it yet, but you should be able to call Coldsteel:SendData( pName, Message ) from any other plugin as in Lua the var Coldsteel is registered global.

You may check existance by comparing Coldsteel with nil
PHP Code:
if(Coldsteel ~= nilthen
  
-- Coldsteel plugin loaded -> run function
  
Coldsteel:SendDatapNameMessage )
end 



RE: Global Function? - Tybor - 03-02-2011

Well, just tried to call a Plugin function from another plugin and failed Sad

You may include other lua files by require statement see http://lua-users.org/wiki/ModulesTutorial

Perhaps FakeTruth can explain the implementation details on the MCServer Lua Scripting??


RE: Global Function? - Dys0n - 03-02-2011

Yea the big issue with lua require is that it points to the wrong folder and will always ask for a dll, But yea would be grreat if FakeTruth could explain it to us


RE: Global Function? - FakeTruth - 03-02-2011

It seems if you create a new folder in the MCServer root called "lua" you can put your 'requires' in that folder, that works.

EDIT: You can also do this
Code:
package.path = "./Plugins/?.lua" .. package.path
require "TestModule"

TestModule.foo()
And keeps TestModule.lua in the Plugins directory