X-600M Users Manual
Appendix G: Lua Scripts
The following is an example of writing to a file in Lua on the X-600M.
' open file for appending
fh = file.open("test.txt", "a");
' check to see if file opened successfully
if fh ~= nul then
' write to file and close it
fh:write("This is a test file created in Lua.\n");
fh:close();
end
Reading and Writing to SQLite Database Files
Lua can be used to create, read, and write to SQLite database files. To achieve this, the X-600M has the
LuaSQLite3 library built into the LUA interpreter. This library allows SQL queries to be run against SQLite
databases, which are essentially just files. SQL and SQLite are beyond the scope of this manual, but
many resources can be found online. At the time of this writing, the documentation for the LuaSQLite3
library can be found at
http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki
. The following is a simple
example of how to create a new table and insert some content:
db = sqlite3.open("test.db");
db:exec[[
CREATE TABLE test (id INTEGER PRIMARY KEY, content);
INSERT INTO test VALUES (NULL, 'Hello World');
INSERT INTO test VALUES (NULL, 'Hello Lua');
INSERT INTO test VALUES (NULL, 'Hello Sqlite3')
]]
db:close()
SQLite database files follow the same rules as files when it comes to their locations. Database files
without a specific path will be placed in the X-600M's internal flash where custom web pages and logs
are stored. Database files with a “/usb/” path will be placed on the external usb drive. Database files
with a “/ram/” path will be placed in the X-600M's internal ram drive. For example:
db = sqlite3.open("test.db");
db = sqlite3.open("/usb/test.db");
db = sqlite3.open("/ram/test.db");
X-600M Specific Functions
The X-600M contains a set of custom functions and libraries that only pertain to the Lua interpreter
running on the X-600M. These functions and libraries, as well as their definitions, are explained below:
time.now()
This function returns a table that holds time information. This table is initialized to the current time.
time.seconds()
This function returns a table that is initialized to the current second counter on the X-600M. This
counter is reset to zero on power up, and when settings are committed. It increments once a
second. The return value from this function can be used for timing purposes.
time.make(month, day, year, hour, minute, second)
This function will return a table that holds time information. The table is initialized to the time
specified in the parameters. The parameters have the following valid ranges:
Xytronix Research & Design, Inc.
Page 127
Содержание X-600M
Страница 1: ...X 600MTitle Page Goes Here...
Страница 6: ...X 600M Users Manual Page 4 Xytronix Research Design Inc...
Страница 99: ...X 600M Users Manual Setup Pages Xytronix Research Design Inc Page 97...
Страница 116: ...Appendix B Installing New Firmware X 600M Users Manual Page 114 Xytronix Research Design Inc...