LUA
COMMANDS
LUA INIT
*no parameters*
Starts the lua system. Must be called before other commands.
LUA DEINIT
*no parameters*
Frees the lua system.
LUA COMPILE FILE
inputfile,outputfile
This function will perform required preprocessing on inputfile, and write the result to
output file. This outputted file can then be called by the LUA EXECUTE FILE command.
This function is only needed if a script is going to be executed frequently, as the preprocessing
could add a performance hit if done very frequently.
LUA EXECUTE FILE
filename,UsePreprocess
Executes the lua code contained in the given file.
If UsePreprocess is set to true, then the DLL will perform the needed processing on the lua script at this time.
Set this to false if the preprocessing has already been done by the LUA COMPILE FILE command.
LUA EXECUTE STRING
code_as_string
Executes the lua code contained in the given string.
LUA CREATE TABLE
table_name
This function creates a new lua table with the given name. You can also
create tables inside of tables.
Some samples:
"testtable"
"testtable[1]"
"testtable.one"
"testtable.one[10]"
LUA GET INT
(variable_name)
returns integer
Gets the value of an integer lua variable with the given name. You can
get values from a table using this function.
Some samples:
"myvar"
"myvar[1]"
"myvar.one[2]"
LUA GET FLOAT
(variable_name)
returns float
Gets the value of a float lua variable with the given name. You can get values from a
table using this function.
LUA GET STRING
(variable_name)
Gets the value of an string lua variable with the given name. You can get values from a
table using this function.
LUA SET INT
variable_name,integer_value
Sets the value of an integer lua variable with the given name. You can
set values for a table using this function
Some samples:
"myvar",10
"myvar[1]",10
"myvar.one[2]",1
LUA SET FLOAT
variable_name,float_value
Sets the value of a float lua variable with the given name.
LUA SET STRING
variable_name,string_value
Sets the value of an string lua variable with the given name.
LUA POP INT
(*no parameters*)
returns integer
Pops an integer off the top lua stack. If the value on top of the stack
is not an integer, an error occurs.
LUA POP FLOAT
(*no parameters*)
returns float
Pops a float off the top lua stack. If the value on top of the stack is
not a float, an error occurs.
LUA POP STRING
(*no parameters*)
returns string
Pops a string off the top lua stack. If the value on top of the stack
is not a string, an error occurs.
LUA TOP IS INT
(*no
parameters*)
returns bool
Returns true if the value on top of the stack is an integer. Otherwise
false is returned.
LUA TOP IS FLOAT
(*no
parameters*)
returns bool
Returns true if the value on top of the stack is a float. Otherwise
false is returned.
LUA TOP IS STRING
(*no
parameters*)
returns bool
Returns true if the value on top of the stack is a string. Otherwise
false is returned.
LUA PUSH INT
integer_value
Pushes an integer onto the lua stack.
LUA PUSH FLOAT
float_value
Pushes a float onto the lua stack.
LUA PUSH STRING
string_value
Pushes a string onto the lua stack.
LUA PUSH FUNCTION
function_name
Pushes a lua function onto the stack to be called shortly. After you
have pushed a lua function onto the stack, you must push the arguments
onto the stack using the "lua push" functions. Then you use the "LUA
CALL FUNCTION" function.
LUA CALL FUNCTION
number_of_arguments,number_of_return_values
Calls the lua function that was previously pushed onto the stack. You
must put the number of arguments that you pushed onto the stack. You
must also tell how many return values there will be. The return values
will be pushed onto the stack where you can retrieve them using the
"lua get" functions.
LUA REGISTER FUNCTION
function_name,pointer_to_function
Registers a dbpro user defined function with lua. You can set the
function name to whatever you want, so long as it doesn't start with a
number or include spaces. To get the function pointer, use IanM's
Matrix1Util_20.dll plugin. The DBPro function must return how many
return values have been pushed onto the stack.
Notes: You cannot compile a script using luac.exe that utilizes user
dbpro functions. If you absolutely must compile the script, you must
not call the functions using their name. Instead call them using
returnval=DBPro("add",arg1,arg2)
Here is some example code:
`This is the dbpro function you want to call from inside a script
function add()
a as integer
b as integer
c as integer
`The parameters of the function are
pushed onto the stack
`Retrieve them by popping them off the
stack
a=lua pop int()
b=lua pop int()
c=a+b
`print the result in dbpro
print c
`return values are pushed back onto the
stack
`you can return more then one value if
you want to.
lua push int c
`return how many return values there are
endfunction 1
`this is the dbpro function that registers the add() function with lua
`you would call this funciton before you execute the lua script that
`accesses the "add()" function
function add_register()
`the "get ptr to prev function()" is in
the Matrix1Util_20.dll plugin
`the command I'm using here returns the
pointer to the function that is
`currently above this one, which is the
"add()" function
lua register function "add",get ptr to
prev function()
endfunction
`This is the lua script file
result=add(1,2)
LUA GET ARG COUNT
(*no parameters*)
returns integer value
This returns how many arguments are being passed to a user dbpro
function from inside a lua script. This function is useful when you
want to call a dbpro user function with a variable number of
arguments
from a lua script.
LUA ERROR OCCURED
(*no
parameters*)
returns boolean value
This function returns true if an error has occured in the lua system.
Otherwise false is returned.
LUA ERROR MSG$
(*no
parameters*)
returns string value
Returns the latest error message generated by the lua system.
LUA ERROR RESET
(*no
parameters*)
Clears all error messages in the lua system.
LUA REGISTER ERROR FUNCTION
pointer_to_function
Allows you to register a user dbpro function that will be called when
an error occures in the lua system. Your user defined function must
take one string argument, which is the error message. You can then do
what you like to handle the error. This saves the hassle of using "LUA
ERROR OCCURED" after every lua function call to check for errors.
Example:
function Error(str as string)
exit prompt "Lua Error!",str
end
endfunction
function Error_register()
lua register error function get ptr to
prev function()
endfunction
CLICK HERE TO RETURN TO THE MAIN MENU