Commit 18896450 authored by jdelange's avatar jdelange

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

   po-hi-c/src/po_hi_lua.c
   - Import capability to execute a script
     contained in a string


git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@3703 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent b111621e
......@@ -45,19 +45,34 @@ typedef struct
/*!
* \fn __po_hi_lua_load (__po_hi_lua_context_t*, const char*);
* \brief Load a LUA script and initialize a LUA context
* \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
* 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
* 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_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_str (__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
......@@ -199,6 +214,7 @@ int __po_hi_lua_get_string (__po_hi_lua_context_t*, char*, char*);
typedef int __po_hi_lua_context_t;
#define __po_hi_lua_load(arg1,arg2)
#define __po_hi_lua_load_str(arg1,arg2)
#define __po_hi_lua_init_function_call(arg1,arg2)
#define __po_hi_lua_perform_function_call(arg1)
#define __po_hi_lua_push_number(arg1,arg2)
......
......@@ -65,19 +65,12 @@ int __po_hi_lua_time_get (lua_State* state)
return 2;
}
int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
int __po_hi_lua_init (__po_hi_lua_context_t* context)
{
if (context == NULL)
{
return __PO_HI_INVALID;
}
if (filename == NULL)
{
return __PO_HI_INVALID;
}
#ifdef __PO_HI_USE_LUA
context->state = lua_open();
......@@ -86,7 +79,48 @@ int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
lua_register (context->state, "time_wait", __po_hi_lua_time_wait);
lua_register (context->state, "time_get", __po_hi_lua_time_get);
lua_register (context->state, "time_delay_until", __po_hi_lua_time_delay_until);
#endif
return __PO_HI_SUCCESS;
}
int __po_hi_lua_load_str (__po_hi_lua_context_t* context, const char* str)
{
if (str == NULL)
{
return __PO_HI_INVALID;
}
if (__po_hi_lua_init (context) != __PO_HI_SUCCESS)
{
return __PO_HI_INVALID;
}
#ifdef __PO_HI_USE_LUA
if (luaL_dostring (context->state,str) != 0)
{
__PO_HI_DEBUG_DEBUG ("[LUA] Fail to load LUA file %s !", filename);
return __PO_HI_INVALID;
}
#endif
return __PO_HI_SUCCESS;
}
int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
{
if (filename == NULL)
{
return __PO_HI_INVALID;
}
if (__po_hi_lua_init (context) != __PO_HI_SUCCESS)
{
return __PO_HI_INVALID;
}
#ifdef __PO_HI_USE_LUA
if (luaL_dofile (context->state,filename) != 0)
{
__PO_HI_DEBUG_DEBUG ("[LUA] Fail to load LUA file %s !", filename);
......
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