Because LuaSQL via Luarocks was not installing - maybe I did not need to do that ...
We went to the odbc driver for a MySQL connection and set up the connection in the windows ODBC connection.
We provide the luasql modules in the Mach installation forlder's "Modules" directory. Luarocks isn't needed or desired unless you have a separate LUA installation that you also want to have lausql connectivity.
I will double check to see if MySQL installer placed them in the %path% variable but I think that is correct - I try to point to the original rather than a copy located elsewhere - as upgrades may / will require that specific version. Just easier.
The MySQL installer didn't put ANYTHING in my PATH. I had to add it myself. My installation is in C:\MySql, so what I added to the PATH environment variable was "C:\MySQL\lib", as that is where the client DLL files were. I also added "C:\MySQL\bin" for grins.
" I set one up and the script ran flawlessly. "
Did you run the script from with in Mach4 ? as a Macro or regular .LUA script ?
I ran the script from the Zerobrane editor. Mach running, do the menu path Operator -> Open Script Editor. Then open the file from my last post. You can then step through the program line by line. Hit F5 to start the program. It will pause on the first line, then hit F10 to advance to the next line. This is called single stepping. Anyway, when it gets to the line where it "requires" the module step past that. If you get an error there then that means luasql can't find the libmysql.dll dependency. The error message is misleading. It says that lua can't find luasql\mysql.dll in the specified directory. However, if you look in that directory, it is indeed there. So yes, that is misleading. But that is more of a Windows thing than a LUA thing.
I intend to call this with a MCode from a GCode script that our machinist wrote .
That will work. I ran it from within the editor to test it. But that code could be put into a macro script and it would be fine.
I meant to ask about this line of code
package.path = package.path .. ";.\\Modules\\?.lua;"
It seems to be a generic folder where we point to .Lua files could you give a quick what it is , and that syntax represents ??
Well. those are the lines I added to the example on the luasql site. That is the LUA equivalent of the PATH environment variable (package.path and package.cpath). They are search directories. So what those lines do is add our Modules directory to the directories that are searched when we try and load a module. So lets examine the string that we appended:
";.\\Modules\\?.lua;"
";" is a path separator, just like what is used in the PATH environment variable.
"." means "current directory". This is used when we provide a relative path. An absolute path could be used as well, such as "C:\\Mach4Hobby\\Modules\\?.lua". But the relative path is used because we always have the Mach installation directory as the current working directory when launching scripts.
"\\Modules\\" is the part of the path that points to the Modules directory.
"?.lua;" specifies the valid file extention.
A lot of times you might do something like this:
package.path = package.path .. ";.\\Modules\\?.lua;.\\Modules\\?.mcs"
This will look for files with *.lua and *.mcs extentions.
package.cpath will always need to look for *.dll files on Windows (*.so files on Linux).
Anyway, look in your Mach installation's Modules directory to see what all we provide for extending LUA. There are modules like luars232 for serial comms and luasockets for network comms, etc...
Steve