Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: cncman172 on March 28, 2016, 10:23:51 AM

Title: Working with LUA
Post by: cncman172 on March 28, 2016, 10:23:51 AM

Hey Gang,
I have tried for the last few weeks to get things to work in LUA and it is challenging.  I can get some very basic code to work but I decided to try the pendant code under examples and each time the code hits
the third line of code in the main() program where it sets the color I get the error below.  Anyone have any idea what I might be doing incorrectly?  Thanks

Russ


function main()
    panel = mcLuaPanelParent;
    mc.mcCntlSetLastError(0, 'panel is parent!!!');
    panel:SetBackgroundColour(wx.wxColour(255,255,255));

**********************

mcLua ERROR: Lua: Error while running chunk
[string "C:\Mach4Hobby\LuaExamples\Pendant Project\Mai..."]:58: attempt to index upvalue 'panel' (a nil value)
stack traceback:
   [string "C:\Mach4Hobby\LuaExamples\Pendant Project\Mai..."]:58: in function 'main'
   [string "C:\Mach4Hobby\LuaExamples\Pendant Project\Mai..."]:382: in main chunk


mcLua ERROR: Lua: Error while running chunk

Debug session finished.
Title: Re: Working with LUA
Post by: DazTheGas on March 28, 2016, 10:38:12 AM
You cannot access the mcLuaPanelParent from a debug session its impossible as the panel parent is the main gui, the main gui is disabled whilst in the editor.

DazTheGas
Title: Re: Working with LUA
Post by: cncman172 on March 28, 2016, 10:55:00 AM
Daz,

Thanks for responding when I put all the code shared in its own panel and just tried to run it it gave the exact same error.

Russ
Title: Re: Working with LUA
Post by: DazTheGas on March 28, 2016, 11:43:13 AM
Heres a snippet from one of my panels if it helps

Code: [Select]
DTG = {}
DTG.panel = nil

        DTG.panel = mcLuaPanelParent;
local window = DTG.panel:GetParent();
window:SetBackgroundColour(wx.wxColour(153,180,209));
window:Refresh();
local wsize = window:GetSize();
DTG.panel:SetSize(wsize);   
     

DazTheGas