Skip to main content

SoS C API of FMOPSolver library 2023 R2

sos_capi_script.h File Reference

Last update: 16.07.2025

C-API to run SoS scripts and exchange basic data. More...

Go to the source code of this file.

Typedefs

typedef void * fmop_script_handle_t
 Contains the data required to post-process any Field-MOP.
 

Functions

Create / Initialize Data Objects

API handling data object life time

DYNARDO_FMOP_API fmop_script_handle_t FMOP_globalScriptEngine ()
 Get the handle to the global script engine from the initialized library. The routine checks if the Lua interpreter is available. If no, it returns 0. If yes, it returns the handle to the Lua interpreter. There is only a single instance available. Repeated calls of this functions always return the same handle. More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_execute (fmop_script_handle_t context, const char *const script)
 Execute Lua script code. The script engine has the ability to parse and execute: More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_createMatrix (fmop_script_handle_t context, const char *const ident, int rows, int cols, const double *const data)
 Creates a tmath.Matrix in Lua script context. This version may be more efficient than creating a matrix through a text based script - at least for large matrices. More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_getMatrix (fmop_script_handle_t context, const char *const ident, int *rows, int *cols, const double **data)
 Retrieves the binary data of a tmath.Matrix existing in the Lua script context The matrix must be saved in a Lua variable. The data can be retrieved in an efficient way by accessing only the data buffers in memory. Do not change the data from outside. Memory management remains with the Lua interpreter. Thus, the garbage collector may free the memory to which the output of this method refers to. More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_createNumber (fmop_script_handle_t context, const char *const ident, double data)
 Creates a double precision floating point number variable in the Lua script context. More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_getNumber (fmop_script_handle_t context, const char *const ident, double *const data)
 Retrieve the pointer to a number variable in the Lua script context. The number is is stored in double precision floating point format. More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_createString (fmop_script_handle_t context, const char *const ident, const char *const data)
 Create a string variable in the Lua script context. More...
 
DYNARDO_FMOP_API fmop_error_t FMOP_script_getString (fmop_script_handle_t context, const char *const ident, const char **data)
 Retrieve the char array pointer to a string variable in the Lua script context. The data can be retrieved in an efficient way by accessing only the data buffers in memory. Do not change the data from outside. Memory management remains with the Lua interpreter. Thus, the garbage collector may free the memory to which the output of this method refers to. More...
 
DYNARDO_FMOP_API bool FMOP_script_identExists (fmop_script_handle_t context, const char *const ident)
 Check whether a variable exists in the Lua script context. More...
 

Detailed Description

C-API to run SoS scripts and exchange basic data.

  • This API follows the Basic exception safety rule. If any of the operations fail, the original data, e.g. the fmop_handle*_t, might have been overwritten, but there should be no resource leak.
  • Return values are typically of type fmop_error_t. To get a human readalbe interpretation forward this value to FMOP_getErrnoString() or call FMOP_getLastErrorString(). More information can be found in the Error Handling section
  • Log messages from the SoS kernel are all bufferd in an internal variable. Unless otherwise stated in a function description, this internal variable gets reset(!) right at the beginning of each function call. Therefore, the user is forced into fetching all log messages of interest before proceeding.
Warning
Concurrent library calls are NOT supported
Unless stated otherwise, function calls overwrite log messages of any previous function call

Function Documentation

◆ FMOP_globalScriptEngine()

DYNARDO_FMOP_API fmop_script_handle_t FMOP_globalScriptEngine ( )

Get the handle to the global script engine from the initialized library. The routine checks if the Lua interpreter is available. If no, it returns 0. If yes, it returns the handle to the Lua interpreter. There is only a single instance available. Repeated calls of this functions always return the same handle.

Returns

◆ FMOP_script_createMatrix()

DYNARDO_FMOP_API fmop_error_t FMOP_script_createMatrix ( fmop_script_handle_t  context,
const char *const  ident,
int  rows,
int  cols,
const double *const  data 
)

Creates a tmath.Matrix in Lua script context. This version may be more efficient than creating a matrix through a text based script - at least for large matrices.

Parameters
contexthandle to a script engine
[in]identthe ident in Lua script of the matrix to be created
[in]rowsthe number of rows of the matrix to be created
[in]colsthe number of columns of the matrix to be created
[in]datathe data array of the matrix to be created. The dimension of the data array must be rows*cols. The matrix data is stored in a column-major format.
Returns

◆ FMOP_script_createNumber()

DYNARDO_FMOP_API fmop_error_t FMOP_script_createNumber ( fmop_script_handle_t  context,
const char *const  ident,
double  data 
)

Creates a double precision floating point number variable in the Lua script context.

Parameters
[in]contexthandle to a script engine
[in]identthe number's variable name
[in]datathe number's value
Returns

◆ FMOP_script_createString()

DYNARDO_FMOP_API fmop_error_t FMOP_script_createString ( fmop_script_handle_t  context,
const char *const  ident,
const char *const  data 
)

Create a string variable in the Lua script context.

Parameters
[in]contexthandle to a script engine
[in]identthe string's variable name
[in]datathe string's text
Returns

◆ FMOP_script_execute()

DYNARDO_FMOP_API fmop_error_t FMOP_script_execute ( fmop_script_handle_t  context,
const char *const  script 
)

Execute Lua script code. The script engine has the ability to parse and execute:

  • any SoS script code (check the command log in the SoS GUI and the scripting examples provided with your SoS installation, in the public documents folder on Windows)
  • any Lua code
    Parameters
    contexthandle to a script engine
    scriptthe Lua script code to be executed
    Returns
    See also
    fmop_error_t

◆ FMOP_script_getMatrix()

DYNARDO_FMOP_API fmop_error_t FMOP_script_getMatrix ( fmop_script_handle_t  context,
const char *const  ident,
int *  rows,
int *  cols,
const double **  data 
)

Retrieves the binary data of a tmath.Matrix existing in the Lua script context The matrix must be saved in a Lua variable. The data can be retrieved in an efficient way by accessing only the data buffers in memory. Do not change the data from outside. Memory management remains with the Lua interpreter. Thus, the garbage collector may free the memory to which the output of this method refers to.

Parameters
[in]contexthandle to a script engine
[in]identthe ident of the tmath.Matrix variable in Lua.
[out]rowsthe number of rows
[out]colsthe number of columns
[out]data*data will point to the matrix data array on output. The dimension of the data array must be rows*cols. The matrix data is stored in a column-major format.
Returns

◆ FMOP_script_getNumber()

DYNARDO_FMOP_API fmop_error_t FMOP_script_getNumber ( fmop_script_handle_t  context,
const char *const  ident,
double *const  data 
)

Retrieve the pointer to a number variable in the Lua script context. The number is is stored in double precision floating point format.

Parameters
[in]contexthandle to a script engine
[in]identthe number's variable name
[out]datacontains the number's memory address on fmop_success. The caller retains ownership of the pointer.
Returns

◆ FMOP_script_getString()

DYNARDO_FMOP_API fmop_error_t FMOP_script_getString ( fmop_script_handle_t  context,
const char *const  ident,
const char **  data 
)

Retrieve the char array pointer to a string variable in the Lua script context. The data can be retrieved in an efficient way by accessing only the data buffers in memory. Do not change the data from outside. Memory management remains with the Lua interpreter. Thus, the garbage collector may free the memory to which the output of this method refers to.

Parameters
[in]contexthandle to a script engine
[in]identthe string's variable name
[out]datacontain's the string's text on fmop_success
Returns

◆ FMOP_script_identExists()

DYNARDO_FMOP_API bool FMOP_script_identExists ( fmop_script_handle_t  context,
const char *const  ident 
)

Check whether a variable exists in the Lua script context.

Parameters
[in]contexthandle to a script engine
[in]identthe variable's name
Returns
  • true: the ident exists
  • false: the ident does not exist

Connect with Ansys