Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: poppabear on November 26, 2014, 02:26:47 PM

Title: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: poppabear on November 26, 2014, 02:26:47 PM
Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"

it is just common calls and coding for doing some mcLua stuff for your screens, macros or whatever. Grouped by subject, with examples.

The two files are the SAME file, one is in MS Word  .doc, and the other is PDF.

PLEASE feel free to "Add To" the document if you think some commonly used thing is missing, and/or if you see a mistake or something could be stated clearer.

Scott





Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: machiner on November 26, 2014, 02:55:35 PM
I am sure others say Thank You, and of course i say Thank You, but Thank You is
too lightweight for this fine work. Your the best!

Why don't you write the manuals ? 
You could charge double and still be worth it,

Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: poppabear on November 26, 2014, 05:03:35 PM
Quote
I am sure others say Thank You, and of course i say Thank You, but Thank You is
too lightweight for this fine work. Your the best!

Nope, getting feedback from forum users is like pulling teeth, much less a thank you...
but, it is just the way it is........

Quote
Why don't you write the manuals ?
You could charge double and still be worth it,

1). I was never asked or even poked at about it.
It is said according to rumor, that a vendor is making the manual(s) and it/they should be out soon, and it/they should be awesome.
Given that, the stuff I am putting out, at best is just a stop-gap measure to help those who are currently struggling up the learning curve slope.
2). Currently, I have charged $0.00 dollars for my work... so, if I charged double that would be Zero Squared!!!   Imagine what I could do with all that MONEY!!  hehehheehe  :)

All Joking aside, I am really glad you like it, and hopefully it has/will help you!!

Happy Thanksgiving!

Scott

Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: pbarratt on November 29, 2014, 07:50:43 PM
Scott,

Sorry for the delay in sending this but I only just got power/cable/internet back after a storm.

I truly appreciate your efforts in this.  It will prove very valuable in getting me going towards understanding mcLUA and writing my own scripts.  Without it, I would have no idea of what functions have been included in Mach 4.

Peter
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: BR549 on November 29, 2014, 09:15:28 PM
Thanks as well Scott,

(;-) TP
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: poppabear on November 30, 2014, 08:04:32 AM
Thank you guys for the feedback!!
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: rcaffin on December 03, 2014, 10:26:49 PM
OK, teeth pulled.

If I read this right, then we now have both a.b format AND c,d format?
I am sure I am getting too old for all this!

Cheers
Roger
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: poppabear on December 04, 2014, 12:04:09 AM
well kinda both...

the first part of the commands is the dot notation part, and the comma delimited stuff is where your parameters are for that command.

You will see for the dot stuff like (there may be anywhere from 0 to more params
depending on what the call is doing):

mc.mcCcccccccc(p1, p2) for example for "Mach Core" commands/functions.
and
scr.***************************x("p1", "p2") for example for "Screen" commands/functions.

Scott
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: rcaffin on December 04, 2014, 01:01:34 AM
I was thinking more in terms of the first part of
hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_ENABLE##);
from Down&Dirty

Of course, since I am not (yet) using lua, it may well be that i have entirely misunderstood what this means.

Cheers
Roger
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: poppabear on December 04, 2014, 02:15:18 AM
oh, lua can return MORE than one value.
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: rcaffin on December 04, 2014, 04:17:01 AM
Quote
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 !

Cheers

Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: poppabear on December 04, 2014, 09:35:10 AM
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;
end

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)
end

Enjoy, Scott
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: rcaffin on December 04, 2014, 04:55:22 PM
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.

Cheers
Roger
PS: I like NoteTab Pro myself.

Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: RICH on December 04, 2014, 05:14:54 PM
Quote
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

RICH
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: dude1 on December 04, 2014, 05:30:39 PM
you mean the second development team squired
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: rcaffin on December 04, 2014, 05:58:02 PM
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.

Cheers
Roger
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: ysymidi on January 02, 2018, 09:01:45 PM
Appreciate your GREAT job!!!
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: rhtuttle on January 19, 2018, 03:54:26 PM
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.

TIA

RT
Title: Re: Here is a Down and Dirty, quick mcLua commonly used coding guide "no frills"
Post by: Pedio on August 03, 2019, 10:05:32 AM
Darn - I had been using every excuse in the book not to learn Lua. Now you have gone and done it, you took away my last excuse...  /sarc off/

Thanks - Now I will try to turn my M4 Kia into a M4 Ferrari.