Hello Guest it is July 15, 2019, 04:57:08 PM

Author Topic: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"  (Read 9234 times)

0 Members and 1 Guest are viewing this topic.

oh, lua can return MORE than one value.
Um ... forgive me, but may I paraphrase that to make sure i have understood?
Are you saying that in lua one can write
a, b = somefunction
and get the same result as
call somefunction(a, b)
in a more conventional (eg Dartmount Basic) language?

If so ... novel !


Offline poppabear

  • *
  •  2,231 2,231
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Ok, here is an Example that shows what is going on, with returning multiple "return values"
the "StopVarForDebugging" in the code, is where you can put a break point in the mcLua debugger when using "F5" to see what the value of everything is.
the function in the example, had the numbers: 2, 3, 5 as parameters passed to it
inside the function it doubles those values, and returns each on individually at double it's value.

I will post the code here, (but the web format will make it look jacked up), and I will attach the code as a .mcs file you can open in NotePad ++ or the editor you use.

Code: [Select]
function DoubleEachParamInput(NumberParam1, NumberParam2, NumberParam3)
local mInst     = 0;
    local inst      = mc.mcGetInstance(mInst);
    local localP1   = NumberParam1; --you could skip this step
    local localP2   = NumberParam2; --and just test the Params
    local localP3   = NumberParam3; --in the error code below directly
    local localRV1  = 0; --local return value 1
    local localRV2  = 0; --local return value 1
    local localRV3  = 0; --local return value 1

    if localP1 == nil then localP1 = 0; end --simple error checking code
    if localP2 == nil then localP2 = 0; end --simple error checking code
    if localP3 == nil then localP3 = 0; end --simple error checking code

    localRV1 = (localP1 * 2);--double param 1
    localRV2 = (localP2 * 2);--double param 2
    localRV3 = (localP3 * 2);--double param 3
    wx.wxMessageBox("Func internal RVs are:\r\n" ..
                    "localRV1 = " .. localRV1 .. "\r\n" ..
                    "localRV2 = " .. localRV2 .. "\r\n" ..
                    "localRV3 = " .. localRV3);
    local StopVarForDebugging = 0;--(F5 debugging var)
    return localRV1, localRV2, localRV3;

if (mc.mcInEditor() == 1) then
    local RV1 = 0; --RV1 = Return Value 1
    local RV2 = 0; --RV2 = Return Value 2
    local RV3 = 0; --RV3 = Return Value 3
    RV1, RV2, RV3 = DoubleEachParamInput(2,3,5);--Pass 3 number params
    wx.wxMessageBox("RETURNED VALUES are:\r\n" ..
                    "RV1 = " .. RV1 .. "\r\n" ..
                    "RV2 = " .. RV2 .. "\r\n" ..
                    "RV3 = " .. RV3);
    local StopVarForDebugging = 0;--(F5 debugging var)

Enjoy, Scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
Good lord - I see. Fascinating - although just pure semantics. Thanks.

I cannot help being reminded of the old and well-known performance comparison between Dartmouth Basic and a (any) modern object-oriented programming language in implementing the standard 'Hello World' test. One line of Basic (print "Hello World") vs half a page of OO code to define and instantiate all the classes needed just to put 'Hello World' on the screen. :-)

Methinks that there is going to be some pain for all the non-programmers in the world when they try to install and use Mach4. A bit like the comparison between installing and using Windows vs Linux - even today.

PS: I like NoteTab Pro myself.

Offline RICH

  • *
  •  7,340 7,340
    • View Profile
there is going to be some pain for all the non-programmers in the world when they try to install and use Mach4

Not really, that's why we have folks like Scott and others!  ;D >:D


Offline dude1

  •  1,253 1,253
    • View Profile
you mean the second development team squired
Ah well ...
'May you live in interesting times ...'

The driver for Mach4 for the ESS has been released, but it seems that there are some residual problems for those who wish to 'play' with Mach4 and then switch back to Mach3 for work. But Greg is working on it.

Appreciate your GREAT job!!!
I just re-read the down and dirty doc and something caught my eye.

Screen Stuff: You can get the names of the object from within the screen designer to include property names
and values. Further note, you can access screen objects from within macros or wizards.

I don't believe you can access screen properties from a macro.  You  can from a button or screen script.  If I am wrong please post a small macro snippet as to how it is done.