Hello Guest it is March 28, 2024, 10:09:41 PM

Author Topic: Understanding Lua  (Read 7561 times)

0 Members and 1 Guest are viewing this topic.

Re: Understanding Lua
« Reply #10 on: December 19, 2016, 05:07:39 PM »
I have it working in a screen button .

Now I don't know how to get it to work in the m110 macro  m110 in mdi causes an error expecting a number

Tired to make a file load.modules.mcs in the macros directory of the profile containing

 local profile = mc.mcProfileGetName(inst)
    local path = mc.mcCntlGetMachDir(inst)
   
    package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"

package.loaded.mcUserScript = nil
us = require "mcUserScript"

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Understanding Lua
« Reply #11 on: December 19, 2016, 05:12:50 PM »
Where are you defining the inst variable your using in the first 2 calls?

inst = mc.mcGetInstance()
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Understanding Lua
« Reply #12 on: December 19, 2016, 05:13:55 PM »
Change the filename to  load_modules.mcs

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Understanding Lua
« Reply #13 on: December 19, 2016, 05:35:10 PM »
Changed file to load_modules.mcs
Added inst = mc.mcGetInstance() to load_modules.mcs

Still not running with m110 in MDI

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Understanding Lua
« Reply #14 on: December 19, 2016, 06:28:39 PM »
This is where I have place files

C:\Mach4Hobby\Modules\mcUserScript.mcs

Code: [Select]
local mcUserScript = {}

function mcUserScript.UserMessage(Message)
if (Message == nil) then --No message was passed
Message = "No message passed" --If no message is passed this will be the default message
end
wx.wxMessageBox(Message)
end

return mcUserScript -- Module End

both the m110.mcs and load_modules.mcs goes in your profiles own macro directory

load_modules.mcs

Code: [Select]
local inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
   
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"

package.loaded.mcUserScript = nil
us = require "mcUserScript"

m110.mcs

Code: [Select]
function m110()

us.UserMessage("This is my message from m110")
 
  end

if (mc.mcInEditor() == 1) then
 m110()
end


This is working within the mdi no problem but still debugging why its not working when called from within gcode, my bet is its something to do with the messagebox not being able to show in the gui from gcode. when running gcode its run within another lua instance that does not have access to the lua instance that is within the gui.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Understanding Lua
« Reply #15 on: December 19, 2016, 06:42:57 PM »
Yep changing the code to below without the messagebox worked fine using mc.mcCntlSetLastError(inst,Message) instead

Code: [Select]
local mcUserScript = {}
local inst = mc.mcGetInstance()

function mcUserScript.UserMessage(Message)
if (Message == nil) then --No message was passed
Message = "No message passed" --If no message is passed this will be the default message
end
--wx.wxMessageBox(Message)
mc.mcCntlSetLastError(inst,Message)
end

return mcUserScript -- Module End

with this now working it should give you something to play with ;-)

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Understanding Lua
« Reply #16 on: December 19, 2016, 07:45:32 PM »
Thanks, it works for me. 
I appreciate the follow through.  Learning!

Keith
Re: Understanding Lua
« Reply #17 on: December 19, 2016, 07:49:58 PM »
Only difference is
C:\Mach4Hobby\Modules\mcUserScript.mcs should be
C:\Mach4Hobby\Modules\mcUserScript.lua ??

Thanks
Keith ???
Re: Understanding Lua
« Reply #18 on: December 19, 2016, 08:01:54 PM »
When I create a gcode file with one line m110 it bombs out the gui?
Re: Understanding Lua
« Reply #19 on: December 19, 2016, 08:05:47 PM »
Gcode FILE  with

G0 X0Y0
M110
G0 X1Y0

works fine