Commit 88a80e10 authored by jdelange's avatar jdelange

* po-hi-c/include/po_hi_lua.h

   po-hi-c/src/po_hi_lua.c
   - Comment the code



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@3674 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent a0389f20
......@@ -46,22 +46,154 @@ typedef struct
typedef int __po_hi_lua_context_t;
#endif
/*!
* \fn __po_hi_lua_load (__po_hi_lua_context_t*, const char*);
* \brief Load a LUA script and initialize a LUA context
*
* This function takes the following arguments:
* - 1st arg: A LUA context that will contain the execution of the script
* - 2nd arg: The name of the script
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to load the script
* - __PO_HI_INVALID: invalid LUA context
* - __PO_HI_SUCCESS: successfully load the script
*/
int __po_hi_lua_load (__po_hi_lua_context_t*, const char*);
/*!
* \fn __po_hi_lua_init_function_call (__po_hi_lua_context_t*, const char*);
* \brief Initialize a function-call within a LUA execution context
*
* This function takes the following arguments:
* - 1st arg: A LUA context that contains the function to be called.
* - 2nd arg: The name of the function to be called.
*
* It returns the potential values:
* - __PO_HI_INVALID: invalid LUA context or invalid function name
* - __PO_HI_SUCCESS: successful operation
*/
int __po_hi_lua_init_function_call (__po_hi_lua_context_t*, const char*);
/*!
* \fn __po_hi_lua_perform_function_call (__po_hi_lua_context_t*);
* \brief Perform a function call previously initalized.
*
* In fact, this function really performs the function calls. When
* you want to make a call to a function from a LUA script, you have
* to perform the following function calls:
* __po_hi_lua_load : load the script
* __po_hi_lua_init_function_call : prepare the function call
* __po_hi_lua_push_XXXX : push the arguments of the function
* __po_hi_lua_perform_function_call : finally make the effective call
*
* This function takes the following arguments:
* - 1st arg: A LUA context that contains the function to be called and was
* used during the previous __po_hi_lua_init_function_call call
*
* It returns the potential values:
* - __PO_HI_ERROR: error while calling the LUA function
* - __PO_HI_SUCCESS: successful operation
*/
int __po_hi_lua_perform_function_call (__po_hi_lua_context_t*);
/*!
* \fn __po_hi_lua_push_number (__po_hi_lua_context_t*, int);
* \brief Push a number value on the stack before calling a LUA function.
*
* This function takes the following arguments:
* - 1st arg: A LUA context that executed a script
* - 2nd arg: The value to put on the stack
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to put the value on the stack
* - __PO_HI_INVALID: invalid LUA context
* - __PO_HI_SUCCESS: successfully push the value on the LUA stack
*/
int __po_hi_lua_push_number (__po_hi_lua_context_t*, int);
/*!
* \fn __po_hi_lua_push_boolean (__po_hi_lua_context_t*, int);
* \brief Push a boolean value on the stack before calling a LUA function.
*
* This function takes the following arguments:
* - 1st arg: A LUA context that executed a script
* - 2nd arg: The value to put on the stack
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to put the value on the stack
* - __PO_HI_INVALID: invalid LUA context
* - __PO_HI_SUCCESS: successfully push the value on the LUA stack
*/
int __po_hi_lua_push_boolean (__po_hi_lua_context_t*, int);
/*!
* \fn __po_hi_lua_push_string (__po_hi_lua_context_t*, char*);
* \brief Push a string value on the stack before calling a LUA function.
*
* This function takes the following arguments:
* - 1st arg: A LUA context that executed a script
* - 2nd arg: The value to put on the stack (a string)
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to put the value on the stack
* - __PO_HI_INVALID: invalid LUA context
* - __PO_HI_SUCCESS: successfully push the value on the LUA stack
*/
int __po_hi_lua_push_string (__po_hi_lua_context_t*, char*);
/*!
* \fn __po_hi_lua_get_boolean (__po_hi_lua_context_t*, char*, int*);
* \brief Get a number value from a global variable from a LUA script
* and inject it in C code.
*
* This function takes the following arguments:
* - 1st arg: A LUA context that executed a script
* - 2nd arg: The global variable name in the LUA script
* - 2rd arg: Pointer to the integer value to be filled.
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to convert the variable to a number
* or non-existent variable
* - __PO_HI_SUCCESS: successfully convert the variable from LUA to C
*
*/
int __po_hi_lua_get_number (__po_hi_lua_context_t*, char*, int*);
/*!
* \fn __po_hi_lua_get_boolean (__po_hi_lua_context_t*, char*, int*);
* \brief Get a boolean value from the global variable from a LUA script
*
* This function takes the following arguments:
* - 1st arg: A LUA context that executed a script
* - 2nd arg: The global variable name in the LUA script
* - 2rd arg: Pointer to the boolean/integer value to be filled.
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to convert the variable to a boolean
* or non-existent variable
* - __PO_HI_SUCCESS: successfully convert the variable from LUA to C
*
*/
int __po_hi_lua_get_boolean (__po_hi_lua_context_t*, char*, int*);
/*!
* \fn __po_hi_lua_get_string (__po_hi_lua_context_t*, char*, char*);
* \brief Get a string value from the global variable from a LUA script
*
* This function takes the following arguments:
* - 1st arg: A LUA context that executed a script
* - 2nd arg: The global variable name in the LUA script
* - 2rd arg: Pointer to the string value to be filled.
*
* It returns the potential values:
* - __PO_HI_FAILURE: fails to convert the variable to a string
* or non-existent variable
* - __PO_HI_SUCCESS: successfully convert the variable from LUA to C
*
*/
int __po_hi_lua_get_string (__po_hi_lua_context_t*, char*, char*);
......
......@@ -12,6 +12,16 @@
int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
{
if (context == NULL)
{
return __PO_HI_INVALID;
}
if (filename == NULL)
{
return __PO_HI_INVALID;
}
#ifdef __PO_HI_USE_LUA
context->state = lua_open();
luaL_openlibs (context->state);
......@@ -25,7 +35,20 @@ int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
int __po_hi_lua_init_function_call (__po_hi_lua_context_t* ctx, const char* fctname)
{
int len = strlen (fctname);
int len;
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
if (fctname == NULL)
{
return __PO_HI_INVALID;
}
len = strlen (fctname);
if ( len >= __PO_HI_LUA_FUNCTION_NAME_MAX_SIZE)
{
return __PO_HI_INVALID;
......@@ -50,7 +73,13 @@ int __po_hi_lua_init_function_call (__po_hi_lua_context_t* ctx, const char* fctn
int __po_hi_lua_perform_function_call (__po_hi_lua_context_t* ctx)
{
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
lua_call (ctx->state, ctx->nb_args, 0);
return __PO_HI_SUCCESS;
}
......@@ -59,42 +88,73 @@ int __po_hi_lua_push_number (__po_hi_lua_context_t* ctx, int val)
ctx->nb_args = ctx->nb_args + 1;
lua_pushnumber (ctx->state, val);
return __PO_HI_SUCCESS;
}
int __po_hi_lua_push_boolean (__po_hi_lua_context_t* ctx, int val)
{
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
ctx->nb_args = ctx->nb_args + 1;
lua_pushboolean (ctx->state, val);
return __PO_HI_SUCCESS;
}
int __po_hi_lua_push_string (__po_hi_lua_context_t* ctx, char* val)
{
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
ctx->nb_args = ctx->nb_args + 1;
lua_pushstring (ctx->state, val);
return __PO_HI_SUCCESS;
}
int __po_hi_lua_get_number (__po_hi_lua_context_t* ctx, char* varname, int* val)
{
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
lua_settop (ctx->state,0);
lua_getglobal (ctx->state,varname);
*val = lua_tonumber (ctx->state,1);
lua_pop (ctx->state,1);
return __PO_HI_SUCCESS;
}
int __po_hi_lua_get_boolean (__po_hi_lua_context_t* ctx, char* varname, int* val)
{
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
return __PO_HI_SUCCESS;
}
int __po_hi_lua_get_string (__po_hi_lua_context_t* ctx, char* varname, char* val)
{
if (ctx == NULL)
{
return __PO_HI_INVALID;
}
return __PO_HI_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment