Hello Guest it is April 24, 2024, 06:27:16 PM

Author Topic: some strange point on last mach4 version  (Read 1508 times)

0 Members and 1 Guest are viewing this topic.

some strange point on last mach4 version
« on: May 23, 2019, 06:47:30 AM »
i use mach4 for some month i install it in china on cnc for woodworking
last 2 day i download the last version and i saw some strange things

1  .i have many M function that i build and inside each there many function ,in each Mcode
     always i put one on headr====>>"local inst = mc.mcGetInstance()",and no need any more
     but this last version its not work ,i must put this statement on each function
2.  i know that mach take all m function in 1 file ,but i never had problem when i had 2 function with  same name
     on 2 different M function,last version its not work ,if same name function not work ,need make each function other
     name
3. the tool path display ,before we had option to control colors now only in screen editor ,and its not  work well
    even you change line thickness its not change
4. last point its opposite not complain but thanks mach team ,they change the CV tuning ,its just work vert good
    i can run  in very good acc dccl  like 2500mm2 in 15m/min and corner perfect
    it wasn't before
thanks
yaakov
Re: some strange point on last mach4 version
« Reply #1 on: May 29, 2019, 12:17:48 AM »
No one have seen that ? Its make impossible to upgrade ....
Any comment?
Re: some strange point on last mach4 version
« Reply #2 on: May 29, 2019, 06:41:53 AM »
Hi,
Mach4 was always intended to be capable of multiple instances. It is necessary therefore to specify
which instance an API call is to apply.

To date Mach4 has only had/been allowed one instance, usually instance '0'. Thus it was often possible to
use inst=0 and reuse that throughout Mach4 without specifying in each scope.

That's changed, it is now closer to the original intention, that is the instance variable MUST be declared WITHIN EACH
AND EVERY SCOPE.

The reason that your existing macros fail is because you took a shortcut when you wrote them and now that shortcut
has failed.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: some strange point on last mach4 version
« Reply #3 on: May 29, 2019, 06:46:47 AM »
Now clear , thanks
Its very important to notice this point,because its mean cant upgrade any system before changing the function inside
Re: some strange point on last mach4 version
« Reply #4 on: May 29, 2019, 07:10:30 AM »
Hi,
yes it is important......and the correct understanding of the extent of each 'scope' is something I still struggle with.

Lua is a stack optimized programming language.

When a new function is called Lua enters a  new scope. All the data and variables used within that scope are stored on a stack.
A stack is a small chunk of contiguous memory locations in the same page of memory as the function code and it is
dynamic, that is the function code and stack is created anew on each occasion its called.When the function completes
and returns the stack goes out of scope and is garbage collected.

Any data or variable which is not within the scope of a function must be global. Any global variable is stored in a
static location in memory and when accessed Lua must stop and resolve the memory access which will often be
in another page of memory. The general rule with Lua is that you should NOT use global variables unless you
have to, you should in preference use local variables.

If you use a variable 'inst' within a function Lua will in the first case try to find that variable on the stack. If it does not
find the variable there it will search in the scope of the calling function and so on up the tree until it finds a valid
variable. Exactly how that search is conducted and where it stops is still somewhat of a mystery to me.
What I have found however is to define ALL, or as many as possible variables as local....it sidesteps all the problems.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: some strange point on last mach4 version
« Reply #5 on: May 30, 2019, 10:32:04 PM »

1  .i have many M function that i build and inside each there many function ,in each Mcode
     always i put one on headr====>>"local inst = mc.mcGetInstance()",and no need any more
     but this last version its not work ,i must put this statement on each function

You should ALWAYS get the instance in every function.  That was the design.  If it worked for you before, it was by accident. 

2.  i know that mach take all m function in 1 file ,but i never had problem when i had 2 function with  same name
     on 2 different M function,last version its not work ,if same name function not work ,need make each function other
     name

In LUA, the last function with the same name wins.  Always.  Now, this version uses LUA 5.3 where the old version you were running may have used LUA 5.2 and that MAY change the order in which functions are loaded. 

It is a programming error to use multiple functions with the same name.  :(

Re: some strange point on last mach4 version
« Reply #6 on: May 31, 2019, 12:33:33 AM »
thanks
but im talking about same name not at same M function
and the problem its that if you make 2 same  function  name ,its not use one of them
its ignore the function
**if i want use the function that i wrote in anther  Mcode ,can i just call it?(they shuld compile to one file all M function)
  or i must write again the function with onther name?
thanks
yaakov

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: some strange point on last mach4 version
« Reply #7 on: June 14, 2019, 01:44:04 PM »
If you want to use common code that can be called from multiple "places" (the GUI or from the M codes), then you need to investigate the use of modules.  LUA modules are analogous to C/C++ DLLs. 

If you are wanting to call a function in one M code script from another M code script, if the function is global, than you can just call it.  Because all of those functions get rolled up into one LUA chunk (mcLua.mcc).  What some people do is create a special file in the macros directory.  Call it anything but make sure it has an extension of .mcs.  For example, MyGlobalFuncs.mcs.  Then you can write functions in that file and it will be included in the mcLua.mcc chunk and all of the functions in that file will be callable from any M code script. 

Steve
Re: some strange point on last mach4 version
« Reply #8 on: June 17, 2019, 09:30:34 AM »
@KatzYaakov, I took the jump to move many of my functions into modules. It was not hard at all, and for me it was really helpful to clean up my screen load script. I wouldn't be afraid to give it a try.