Commit a0389f20 authored by jdelange's avatar jdelange

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

   po-hi-c/src/po_hi_lua.c
   - Finish LUA integration

 * po-hi-c/configure.ac
   - Put appropriate linker flag to compile with LUA
     on Native


git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@3672 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent df775abc
......@@ -66,6 +66,8 @@ esac
AC_CHECK_LIB(socket, socket, [NATIVE_LDFLAGS="${NATIVE_LDFLAGS} -lsocket"])
AC_CHECK_LIB(lua5.1, luaL_openlibs, [NATIVE_LDFLAGS="${NATIVE_LDFLAGS} -llua5.1"])
AC_CHECK_LIB(lua5.1, luaL_openlibs, [])
AC_SUBST(NATIVE_CFLAGS)
AC_SUBST(NATIVE_LDFLAGS)
AC_SUBST(SIMULINK_LDFLAGS)
......
......@@ -19,6 +19,10 @@
#include <unistd.h>
#include <po_hi_returns.h>
#ifdef POSIX
#include <string.h>
#endif
#ifdef HAVE_LIBLUA5_1
#define __PO_HI_USE_LUA
#else
......@@ -29,9 +33,37 @@
#include <lua5.1/lua.h>
#include <lua5.1/lualib.h>
#include <lua5.1/lauxlib.h>
#define __PO_HI_LUA_FUNCTION_NAME_MAX_SIZE 100
typedef struct
{
lua_State* state;
int nb_args;
char function_name[__PO_HI_LUA_FUNCTION_NAME_MAX_SIZE];
}__po_hi_lua_context_t;
#else
typedef int __po_hi_lua_context_t;
#endif
int __po_hi_lua_load (const char*, const char*);
int __po_hi_lua_load (__po_hi_lua_context_t*, const char*);
int __po_hi_lua_init_function_call (__po_hi_lua_context_t*, const char*);
int __po_hi_lua_perform_function_call (__po_hi_lua_context_t*);
int __po_hi_lua_push_number (__po_hi_lua_context_t*, int);
int __po_hi_lua_push_boolean (__po_hi_lua_context_t*, int);
int __po_hi_lua_push_string (__po_hi_lua_context_t*, char*);
int __po_hi_lua_get_number (__po_hi_lua_context_t*, char*, int*);
int __po_hi_lua_get_boolean (__po_hi_lua_context_t*, char*, int*);
int __po_hi_lua_get_string (__po_hi_lua_context_t*, char*, char*);
#endif
......
......@@ -10,16 +10,91 @@
#include <po_hi_lua.h>
int __po_hi_lua_load (const char* filename, const char* functionname)
int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
{
#ifdef __PO_HI_USE_LUA
lua_State * state;
state = lua_open();
luaL_openlibs(state);
if (luaL_dofile (state,filename) != 0)
context->state = lua_open();
luaL_openlibs (context->state);
if (luaL_dofile (context->state,filename) != 0)
{
return __PO_HI_INVALID;
}
#endif
return __PO_HI_SUCCESS;
}
int __po_hi_lua_init_function_call (__po_hi_lua_context_t* ctx, const char* fctname)
{
int len = strlen (fctname);
if ( len >= __PO_HI_LUA_FUNCTION_NAME_MAX_SIZE)
{
return __PO_HI_INVALID;
}
memset (ctx->function_name, '\0', __PO_HI_LUA_FUNCTION_NAME_MAX_SIZE);
memcpy (ctx->function_name, fctname, len);
ctx->nb_args = 0;
lua_getglobal(ctx->state, fctname);
if (!lua_isfunction(ctx->state,-1))
{
lua_pop(ctx->state,1);
return __PO_HI_INVALID;
}
return __PO_HI_SUCCESS;
}
int __po_hi_lua_perform_function_call (__po_hi_lua_context_t* ctx)
{
lua_call (ctx->state, ctx->nb_args, 0);
}
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);
}
int __po_hi_lua_push_boolean (__po_hi_lua_context_t* ctx, int val)
{
ctx->nb_args = ctx->nb_args + 1;
lua_pushboolean (ctx->state, val);
}
int __po_hi_lua_push_string (__po_hi_lua_context_t* ctx, char* val)
{
ctx->nb_args = ctx->nb_args + 1;
lua_pushstring (ctx->state, val);
}
int __po_hi_lua_get_number (__po_hi_lua_context_t* ctx, char* varname, int* val)
{
lua_settop (ctx->state,0);
lua_getglobal (ctx->state,varname);
*val = lua_tonumber (ctx->state,1);
lua_pop (ctx->state,1);
}
int __po_hi_lua_get_boolean (__po_hi_lua_context_t* ctx, char* varname, int* val)
{
}
int __po_hi_lua_get_string (__po_hi_lua_context_t* ctx, char* varname, char* val)
{
}
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