RHTuttle posted in January about launching functions as coroutines from his scripts using load_modules.mcs to load his custom module, a user module, and a button script
http://www.machsupport.com/forum/index.php/topic,36474.0.htmlI had no success trying to duplicate his efforts. I reduced my code to a minor test case, and it seems that I'm doing something wrong regarding load_modules.mcs.
The file 'load_modules.mcs' in my profile's '\Macros' subdirectory
---------------------------------------------------------------
-- Load modules that you want to be able to use from Mcodes
---------------------------------------------------------------
inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"
--package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;"
--ErrorCheck module
package.loaded.mcErrorCheck = nil
ec = require "mcErrorCheck"
ph = require "phModule" -- resides: C:\Mach4Hobby\Profiles\MyCNC\Modules
'phModule.lua' in my profile's '\Modules' subdirectory.
local phModule = {}
function phModule.bigMac()
mc.mcCntlSetLastError(inst, "Special Sauce?")
end
return phModule
Button code
ph.bigMac()
When I activate the screen button, I get the following error message:
C:\Mach4Hobby\ScreenScript.lua:1029: attempt to index global 'ph' (a nil value)
stack traceback:
C:\Mach4Hobby\ScreenScript.lua:1029: in function <C:\Mach4Hobby\ScreenScript.lua:1028>
However, if I add the load_modules code to the Screen Load Script, my button functions as expected.
--My Stuff (Paul)
ph = require "phModule"
Yes, I got the code working, but I'm perplexed as to what I was doing wrong initially. Any and all help much appreciated.