Class LuaHelper

java.lang.Object
com.mouseviator.fsuipc.helpers.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

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
  • Field Details

    • PARAMETER_OFFSET

      public static final int PARAMETER_OFFSET
      Offset for parameter passing for the control offset below
      See Also:
      Constant Field Values
    • CONTROL_OFFSET

      public static final int CONTROL_OFFSET
      Offset 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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is 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 of FSUIPC to 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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null will be returned also if fsuipc is null.
    • lua

      public LuaHelper.LuaResult lua​(java.lang.String luaProgram)
      This function will construct data requests required by FSUIPC to run specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA command.
      Parameters:
      luaProgram - The name of the lua program to run. Without the .lua extension.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • lua

      public LuaHelper.LuaResult lua​(java.lang.String luaProgram, FSUIPC fsuipc)
      This function will construct data requests required by FSUIPC to run specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • lua

      public LuaHelper.LuaResult lua​(java.lang.String luaProgram, int luaParam)
      This function will construct data requests required by FSUIPC to run specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA command.
      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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • lua

      public LuaHelper.LuaResult lua​(java.lang.String luaProgram, int luaParam, FSUIPC fsuipc)
      This function will construct data requests required by FSUIPC to run specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaValue

      public LuaHelper.LuaResult luaValue​(java.lang.String luaProgram, int luaParam)
      This function will construct data requests required by FSUIPC to send parameter to specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_VALUE command. 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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaValue

      public LuaHelper.LuaResult luaValue​(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 the LuaHelper.LuaControlRequestCommand.LUA_VALUE command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaDebug

      public LuaHelper.LuaResult luaDebug​(java.lang.String luaProgram)
      This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_DEBUG command.
      Parameters:
      luaProgram - The name of the lua program to run and debug. Without the .lua extension.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaDebug

      public LuaHelper.LuaResult luaDebug​(java.lang.String luaProgram, FSUIPC fsuipc)
      This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_DEBUG command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaDebug

      public LuaHelper.LuaResult luaDebug​(java.lang.String luaProgram, int luaParam)
      This function will construct data requests required by FSUIPC to run and debug specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_DEBUG command.
      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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaDebug

      public LuaHelper.LuaResult luaDebug​(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 the LuaHelper.LuaControlRequestCommand.LUA_DEBUG command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaKill

      public LuaHelper.LuaResult luaKill​(java.lang.String luaProgram)
      This function will construct data requests required by FSUIPC to kill specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_KILL command.
      Parameters:
      luaProgram - The name of the lua program to kill. Without the .lua extension.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaKill

      public LuaHelper.LuaResult luaKill​(java.lang.String luaProgram, FSUIPC fsuipc)
      This function will construct data requests required by FSUIPC to kill specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_KILL command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaKillAll

      public IDataRequest 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

      public LuaHelper.LuaResult luaSet​(java.lang.String luaProgram, int luaFlag)
      This function will construct data requests required by FSUIPC to set flag for specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_SET command.
      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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaSet

      public LuaHelper.LuaResult luaSet​(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 the LuaHelper.LuaControlRequestCommand.LUA_SET command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaClear

      public LuaHelper.LuaResult luaClear​(java.lang.String luaProgram, int luaFlag)
      This function will construct data requests required by FSUIPC to clear flag for specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_CLEAR command.
      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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaClear

      public LuaHelper.LuaResult luaClear​(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 the LuaHelper.LuaControlRequestCommand.LUA_CLEAR command. 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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.
    • luaToggle

      public LuaHelper.LuaResult luaToggle​(java.lang.String luaProgram, int luaFlag)
      This function will construct data requests required by FSUIPC to toggle flag for specified lua program (Performs the LuaHelper.LuaControlRequestCommand.LUA_SET command. 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.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned.
    • luaToggle

      public LuaHelper.LuaResult luaToggle​(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 the LuaHelper.LuaControlRequestCommand.LUA_SET command.
      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 of FSUIPC to register with for one time processing.
      Returns:
      Will return an instance of LuaHelper.LuaResult when both required data requests are successfully created. The creation of control request may fail if the luaProgram is null or blank. In that case, null will be returned. Null we be returned also if fsuipc is null.