Class LuaHelper
public class LuaHelper
extends java.lang.Object
This class implements a helper to manipulate Lua scripts using FSUIPC.
Manipulating Lua via FSUIPC requires 2 data requests, because it works with 2 offsets. Many functions in this class
return both of them in an instance of LuaHelper.LuaResult. The main offset in use is 0D70, in which you write a string
telling FSUIPC what to do with what lua script. I call it here a "control request" and it is the LuaHelper.LuaResult.getControlRequest(). The next offset is 0D6C and I reference it as "parameter request" here. Because it is the parameter for lua script
/ operation with the lua script. You will find this request in the result object as LuaHelper.LuaResult.getParamRequest().
There are various functions for all the things we can do with the lua programs via FSUIPC - start them, kill them, send parameter to them and set,clear or toggle one of the 255 available flags.
Some functions also accepts an instance of FSUIPC class. These functions will also register the generated
requests with given FSUIPC instance for one-time processing
Running a lua program example
The code below uses helper function to build requests to run the "hello world.lua" program. The helper function will build the required data requests and we just register them for processing and process them. Whether it worked or not needs to be looked in the sim - in the FSUIPC console window or FSUIPC log file. There should be line saying Hello world....
//
// Running lua test
//
LuaHelper luaHelper = new LuaHelper();
//hello wordl script
LuaHelper.LuaResult helloworldreq = luaHelper.lua("hello world");
fsuipc.addOneTimeRequest(helloworldreq.getParamRequest());
fsuipc.addOneTimeRequest(helloworldreq.getControlRequest());
if (fsuipc.processRequestsOnce() == FSUIPC.PROCESS_RESULT_OK) {
System.out.println("The requested script should have been run!");
}
or shorter way:
LuaHelper luaHelper = new LuaHelper();
LuaHelper.LuaResult helloworldreq = luaHelper.lua("hello world", fsuipc);
if (fsuipc.processRequestsOnce() == FSUIPC.PROCESS_RESULT_OK) {
System.out.println("The requested script should have been run!");
}
The other operations - killing a lua program, sending a param to lua program or manipulation lua program flags,
follow the same logic. The only exception is the luaKillAll() function, which return only one data
request and works like most of the functions in other helper classes. You just need to register the returned request
for one-time of continual processing (well, that actually makes no sense) with FSUIPC instance. If you use the
function that that registers the requests with FSUIPC, you may not need the resulting object at all. Unless you
registered them for continual processing and need to remove them from processing later on.
Sending parameter to lua program
Ok, one more example using the short way:
LuaHelper luaHelper = new LuaHelper();
LuaHelper.LuaResult helloworldreq = luaHelper.luaValue("flag_param", 40, fsuipc);
if (fsuipc.processRequestsOnce() == FSUIPC.PROCESS_RESULT_OK) {
System.out.println("Parameter should be 40 for program: flag_param.lua");
}
If you will be registering the requests yourself, make sure that you register them in this order
- 1. Parameter request (
LuaHelper.LuaResult.getParamRequest()) - 2. Control request (
LuaHelper.LuaResult.getControlRequest())
You can also skip the helper functions and use the most raw function to create the requests: luaRequest(java.lang.String, int, com.mouseviator.fsuipc.helpers.LuaHelper.LuaControlRequestCommand) or
luaRequest(java.lang.String, int, com.mouseviator.fsuipc.helpers.LuaHelper.LuaControlRequestCommand, com.mouseviator.fsuipc.FSUIPC, boolean).
Or even use request and other supporting classes defined in this helper class and write the create function by yourself.
- Author:
- Mouseviator
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLuaHelper.LuaControlRequestThis class implements Lua control request.static classLuaHelper.LuaControlRequestCommandAn enumeration representing a command forLuaHelper.LuaControlRequest.static classLuaHelper.LuaParamRequestThis class implements lua parameter request.static classLuaHelper.LuaResultA class representing a result for lua control helper functions in the classLuaHelper. -
Field Summary
Fields Modifier and Type Field Description static intCONTROL_OFFSETOffset to tell FSUIPC what to do with lua script, LVar or Macrostatic intPARAMETER_OFFSETOffset for parameter passing for the control offset below -
Constructor Summary
Constructors Constructor Description LuaHelper() -
Method Summary
Modifier and Type Method Description LuaHelper.LuaResultlua(java.lang.String luaProgram)This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand.LuaHelper.LuaResultlua(java.lang.String luaProgram, int luaParam)This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand.LuaHelper.LuaResultlua(java.lang.String luaProgram, int luaParam, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand.LuaHelper.LuaResultlua(java.lang.String luaProgram, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand.LuaHelper.LuaResultluaClear(java.lang.String luaProgram, int luaFlag)This function will construct data requests required by FSUIPC to clear flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_CLEARcommand.LuaHelper.LuaResultluaClear(java.lang.String luaProgram, int luaFlag, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to clear flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_CLEARcommand.LuaHelper.LuaResultluaDebug(java.lang.String luaProgram)This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand.LuaHelper.LuaResultluaDebug(java.lang.String luaProgram, int luaParam)This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand.LuaHelper.LuaResultluaDebug(java.lang.String luaProgram, int luaParam, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand.LuaHelper.LuaResultluaDebug(java.lang.String luaProgram, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand.LuaHelper.LuaResultluaKill(java.lang.String luaProgram)This function will construct data requests required by FSUIPC to kill specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_KILLcommand.LuaHelper.LuaResultluaKill(java.lang.String luaProgram, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to kill specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_KILLcommand.IDataRequestluaKillAll()This function will generate request to send FSUIPC control to kill all running lua programs.LuaHelper.LuaResultluaRequest(java.lang.String luaProgram, int luaParam, LuaHelper.LuaControlRequestCommand luaCommand)This function will construct data requests required by FSUIPC to perform given operation with given lua program.LuaHelper.LuaResultluaRequest(java.lang.String luaProgram, int luaParam, LuaHelper.LuaControlRequestCommand luaCommand, FSUIPC fsuipc, boolean continual)This function will construct data requests required by FSUIPC to perform given operation with given lua program.LuaHelper.LuaResultluaSet(java.lang.String luaProgram, int luaFlag)This function will construct data requests required by FSUIPC to set flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand.LuaHelper.LuaResultluaSet(java.lang.String luaProgram, int luaFlag, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to set flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand.LuaHelper.LuaResultluaToggle(java.lang.String luaProgram, int luaFlag)This function will construct data requests required by FSUIPC to toggle flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand.LuaHelper.LuaResultluaToggle(java.lang.String luaProgram, int luaFlag, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to toggle flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand.LuaHelper.LuaResultluaValue(java.lang.String luaProgram, int luaParam)This function will construct data requests required by FSUIPC to send parameter to specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_VALUEcommand.LuaHelper.LuaResultluaValue(java.lang.String luaProgram, int luaParam, FSUIPC fsuipc)This function will construct data requests required by FSUIPC to send parameter to specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_VALUEcommand.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
PARAMETER_OFFSET
public static final int PARAMETER_OFFSETOffset for parameter passing for the control offset below- See Also:
- Constant Field Values
-
CONTROL_OFFSET
public static final int CONTROL_OFFSETOffset to tell FSUIPC what to do with lua script, LVar or Macro- See Also:
- Constant Field Values
-
-
Constructor Details
-
LuaHelper
public LuaHelper()
-
-
Method Details
-
luaRequest
public LuaHelper.LuaResult luaRequest(java.lang.String luaProgram, int luaParam, LuaHelper.LuaControlRequestCommand luaCommand)This function will construct data requests required by FSUIPC to perform given operation with given lua program. Any lua program operation requires 2 data requests to be created. One is parameter for lua program or flag being modified by the lua request. The other is the control request, which tells FSUIPC what to do with specified lua program.- Parameters:
luaProgram- The name of the lua program. Without the .lua extension.luaParam- Parameter for the lua program or the number of the flag (0-255) being modified.luaCommand- What to do with the lua program.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaRequest
public LuaHelper.LuaResult luaRequest(java.lang.String luaProgram, int luaParam, LuaHelper.LuaControlRequestCommand luaCommand, FSUIPC fsuipc, boolean continual)This function will construct data requests required by FSUIPC to perform given operation with given lua program. Any lua program operation requires 2 data requests to be created. One is parameter for lua program or flag being modified by the lua request. The other is the control request, which tells FSUIPC what to do with specified lua program.- Parameters:
luaProgram- The name of the lua program. Without the .lua extension.luaParam- Parameter for the lua program or the number of the flag (0-255) being modified.luaCommand- What to do with the lua program.fsuipc- An instance ofFSUIPCto register requests with.continual- Whether to register requests for continual processing or one-time processing. True for continual.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null will be returned also iffsuipcis null.
-
lua
This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand.- Parameters:
luaProgram- The name of the lua program to run. Without the .lua extension.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
lua
This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to run. Without the .lua extension.fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
lua
This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand.- Parameters:
luaProgram- The name of the lua program to run. Without the .lua extension.luaParam- Parameter for the lua program.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
lua
This function will construct data requests required by FSUIPC to run specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUAcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to run. Without the .lua extension.luaParam- Parameter for the lua program.fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaValue
This function will construct data requests required by FSUIPC to send parameter to specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_VALUEcommand. Only integer parameters are supported (because FSUIPC simply expects 4 byte integer as the parameter).- Parameters:
luaProgram- The name of the lua program to send parameter to. Without the .lua extension.luaParam- Parameter for the lua program.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaValue
This function will construct data requests required by FSUIPC to send parameter to specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_VALUEcommand. Only integer parameters are supported (because FSUIPC simply expects 4 byte integer as the parameter). The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to send parameter to. Without the .lua extension.luaParam- Parameter for the lua program.fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaDebug
This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand.- Parameters:
luaProgram- The name of the lua program to run and debug. Without the .lua extension.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaDebug
This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to run and debug. Without the .lua extension.fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaDebug
This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand.- Parameters:
luaProgram- The name of the lua program to run and debug. Without the .lua extension.luaParam- Parameter for the lua program or the number of the flag (0-255) being modified.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaDebug
This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_DEBUGcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to run and debug. Without the .lua extension.luaParam- Parameter for the lua program or the number of the flag (0-255) being modified.fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaKill
This function will construct data requests required by FSUIPC to kill specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_KILLcommand.- Parameters:
luaProgram- The name of the lua program to kill. Without the .lua extension.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaKill
This function will construct data requests required by FSUIPC to kill specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_KILLcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to kill. Without the .lua extension.fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaKillAll
This function will generate request to send FSUIPC control to kill all running lua programs. NOTE that this is the only function in this helper that does return only one request!- Returns:
- A data request to kill all running lua programs.
-
luaSet
This function will construct data requests required by FSUIPC to set flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand.- Parameters:
luaProgram- The name of the lua program to set flag for. Without the .lua extension.luaFlag- A flag (0-255) to set for specified lua program. (Note that validity of this value is not checked!)- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaSet
This function will construct data requests required by FSUIPC to set flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to set flag for. Without the .lua extension.luaFlag- A flag (0-255) to set for specified lua program. (Note that validity of this value is not checked!)fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaClear
This function will construct data requests required by FSUIPC to clear flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_CLEARcommand.- Parameters:
luaProgram- The name of the lua program to clear flag for. Without the .lua extension.luaFlag- A flag (0-255) to clear for specified lua program. (Note that validity of this value is not checked!)- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaClear
This function will construct data requests required by FSUIPC to clear flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_CLEARcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to clear flag for. Without the .lua extension.luaFlag- A flag (0-255) to clear for specified lua program. (Note that validity of this value is not checked!)fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-
luaToggle
This function will construct data requests required by FSUIPC to toggle flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand. The function will also register the requests with FSUIPC for one-time processing.- Parameters:
luaProgram- The name of the lua program to toggle flag for. Without the .lua extension.luaFlag- A flag (0-255) to toggle for specified lua program. (Note that validity of this value is not checked!)- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned.
-
luaToggle
This function will construct data requests required by FSUIPC to toggle flag for specified lua program (Performs theLuaHelper.LuaControlRequestCommand.LUA_SETcommand.- Parameters:
luaProgram- The name of the lua program to toggle flag for. Without the .lua extension.luaFlag- A flag (0-255) to toggle for specified lua program. (Note that validity of this value is not checked!)fsuipc- An instance ofFSUIPCto register with for one time processing.- Returns:
- Will return an instance of
LuaHelper.LuaResultwhen both required data requests are successfully created. The creation of control request may fail if theluaProgramis null or blank. In that case, null will be returned. Null we be returned also iffsuipcis null.
-