Hi,
I hope I'm not belabouring the point or trying to 'teach my Grandmother to suck eggs' but we have a perfect example of one of Lua's strengths right here.
All Lua variables are a table. The syntax for addressing a table is the name of the table followed by a period followed by the name of the entry in that table.
I'm more familiar with FORTRAN and C and the elements of an array are sequentially numbered integers 0,1,2, etc. In Lua however an entry name may be a number or
a string and any mixture thereof.
As an example:
mc = the name of the table
X_AXIS = Name of an entry in the table
mcJogSetRate() = Name of an entry in the table.
Note the one entry, namely X_AXIS equates to just a number. in this case 0. The other entry, namely mcJogSetRate() is a function. Thus the entries in any given table
my be a mixture of strings, numbers or functions. Compare that to C where all elements in the array must be of the same type, say float.
This is a perfect example of the principle of 'a function as a first class value', that is to say a function can be bandied about as if its just a number.....extremely handy
and much of Lua's flexibility comes from use and re-use of that property.
The 'mc' table must be huge. Think of all the APIs like mc.mcJogSetRate() and the many hundreds like it, mc.X_AXIS and many dozens of other numeric assignments
including mc.ISIG_INPUT43 for example.
Again apologies for hijacking the thread but this property of Lua intrigues me greatly.
Craig
Exactly, I like this property myself, especially if dealing with data from a variety of sensors or inputs. Building data structure arrays is a time consuming process in C.
As the thread initially states, I have been unsuccessful at reliably writing anything to registers (obviously due to some flaw in my code/understanding of the mach registers)).
Are the registers (iRegs, etc...) actually also simply entries in a LUA table as well? Or are they global variables? They seem too flexible to be actual firmware registers to me, but then again that level of detail is past my knowledge.