Let me try and clear this one up about modules before you awake........
Modules in Lua - wxLua are like other languages classes, now these classes hold functions (class of functions). Now when declaring these Modules wx or lua need to know where to look, this is where the package.path comes in.
Like all other languages you declare the path which is "global" so no need to keep declaring all over the place.
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"
So lets break this down to what wxlua sees when we require a module called newClass, first lets look in "Mach4Hobby\Profiles\"current profile name"\Modules and look for newClass.lua and if not found then lets look in Mach4Hobby\Modules for newClass.lua - so does it have to be .lua extension?? - nope it can be anything you want
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.mcs;"
The above will look in the same directories but also look in the last directory for newClass.mcs - so now we can find modules lets look at the module
local myClass = {}
function myClass.test()
wx.wxMessageBox("Nothing to see here")
end
function test()
wx.wxMessageBox("Still Nothing to see here")
end
return myClass
The above will create a class called myClass and declare myClass.test() as available to public to use, however the function test() is private and can only be used by the class.
Now lets load the class from mach4, first make an instance of the class and call it what you like
message = require "newClass" - wxlua will now search our path from earlier for the newClass file and make a new instance of the class called myClass contained in the file, now to use a function in the class we need to call it with the instance of the class we created "message", so to run the test function we would use message.test() - this will now run and in this case show a messagebox.
If wanted you can use many instances of the same class
message = require "newClass"
message2 = require "newClass"
each one of the buttons or dro`s etc in the editor create an instance of a class for example.
DazTheGas
Time for coffee and biccy now