Hello Guest it is March 28, 2024, 11:27:33 AM

Author Topic: Understanding Lua  (Read 7559 times)

0 Members and 1 Guest are viewing this topic.

Re: Understanding Lua
« Reply #20 on: December 19, 2016, 08:48:37 PM »
Works fine in all instances button script, g code, mfunction, even with wx.wxMessageBox(Message)

Keith

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Understanding Lua
« Reply #21 on: December 19, 2016, 09:33:46 PM »
Great! Can you give us a summary of why that wasn't the case on the first try? This helps make adjustments to samples, docs, etc.
;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!
Re: Understanding Lua
« Reply #22 on: December 20, 2016, 08:45:04 AM »
Next post is correct I believe
« Last Edit: December 20, 2016, 08:57:41 AM by thespindoctor »
Re: Understanding Lua
« Reply #23 on: December 20, 2016, 08:56:53 AM »
I think your original code was successful except for the filename change to load_modules.mcs from load.modules.mcs

Daz suggestions changed the message method and

C:\Mach4Hobby\Modules\mcUserScript.mcs should be
C:\Mach4Hobby\Modules\mcUserScript.lua

Changes from Daz quote made below

This is where I have placed files

C:\Mach4Hobby\Modules\mcUserScript.lua

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)
mc.mcCntlSetLastError(inst,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

DazTheGas

[/quote]
« Last Edit: December 20, 2016, 08:59:45 AM by thespindoctor »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Understanding Lua
« Reply #24 on: December 20, 2016, 09:31:58 AM »
I am confused. Unless I am misunderstanding you, in the script I originally posted both of those are correct.

Quote
I think your original code was successful except for the filename change to load_modules.mcs from load.modules.mcs

C:\Mach4Hobby\Modules\mcUserScript.mcs should be
C:\Mach4Hobby\Modules\mcUserScript.lua

The reason I point this out is because it really shines a light on the old saying, garbage in is garbage out. To us humans those are very simple mistakes and easily overlooked. But to a computer your talking about different planets all together. I plan on using this as an example many will see over time and I want to make sure it is 100% accurate. I know it works here, I have tested it many times but if exactly what I posted does not work on your end I need to figure out why.
;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!
Re: Understanding Lua
« Reply #25 on: December 20, 2016, 03:02:35 PM »
Those were my mistakes and happened because I did not have the file naming conventions correct.  I think it is correct now.  The way Daz posted it was easier for me to see where to save each file type and how to name each file.  I will proof it again tonight after the first day
of skiing Copper Mountain now.  Not sure why Daz had trouble in a G code file.

Keith

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Understanding Lua
« Reply #26 on: December 20, 2016, 03:38:23 PM »
A big oooooops from me  ??? ??? ??? ??? :o :o :'(,  just had a rather interesting debug session and yep all works well.

It all boils down to forgetting what you did previously, I already have a macro functions file in my macro directory and forgot so by adding the load_modules.mcs file overwrites my "package.path" with the one containing the .lua extension.

my package.path normally consists of both mcs and lua

Code: [Select]
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"
package.path = package.path ..path .. "\\Profiles\\" .. profile .. "\\Modules\\?.mcs;" .. path .. "\\Modules\\?.mcs;"

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Understanding Lua
« Reply #27 on: December 20, 2016, 04:27:23 PM »
Awesome feedback guys! Thanks!

Have fun skiing! Makes me jealous.  ;D

Thats a good find Daz. That could have taken a very long time to find especially if you did not have intimate knowledge of your setup. No shame in it either. This is what happens. To me it is another perfect example. This is why once folks start customizing any little part, they own it all and have to. This is why we ask all testing be done with all things default. Now with this example no way to do it because we are helping to customize but folks need to always start with a profile (copied) that has all things default, change a little and test. That way its easy to back out till you find the error if you run into one.

It also lets folks see that even the best run into issues at times and just have to dig in and figure out whats going on. Sometimes knowing what doesn't work is as valuable as knowing what does. I remember a bit of code stumping me not so long ago. The problem............ inst was not defined. Another fella spotted it right off. Obviously I understand its importance but being imperfect comes natural.  ;D

I may be wrong but I think topics like this one will be priceless for those starting out and willing to follow.
;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!