First functionnal lua test with internal lib

This commit is contained in:
Edouard Dupin 2012-05-30 10:23:14 +02:00
parent 038be3ef3e
commit 49e62a10d1
4 changed files with 45 additions and 28 deletions

View File

@ -26,6 +26,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Android \
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
-DDATA_IN_APK \
-DLUA_COMPAT_ALL \
-frtti
else
LOCAL_CFLAGS := -D__PLATFORM__Android \
@ -35,6 +36,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Android \
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
-DDATA_IN_APK \
-DLUA_COMPAT_ALL \
-frtti
endif

View File

@ -26,6 +26,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
-DEWOL_USE_FREE_TYPE \
-DLUA_COMPAT_ALL \
-Wall
else
@ -35,6 +36,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
-DEWOL_DEBUG_LEVEL=3 \
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-release\"" \
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
-DLUA_COMPAT_ALL \
-DEWOL_USE_FREE_TYPE
endif

View File

@ -31,7 +31,7 @@
* @param ---
* @return ---
*/
ewol::GameElement::GameElement(SceneElement & sceneElement, etk::UString& tmpName) : m_sceneElement(sceneElement), m_fileNameConfig(tmpName)
ewol::GameElement::GameElement(SceneElement & sceneElement, etk::UString& tmpName) : m_fileNameConfig(tmpName), m_sceneElement(sceneElement)
{
m_group = -1;
m_type = -1;
@ -88,8 +88,15 @@ etkFloat_t quadDist(coord2D_ts pos1, coord2D_ts pos2)
#include <lua/lua.hpp>
extern "C" {
#include <lua/luaconf.h>
#include <lua/lauxlib.h>
}
extern "C" {
const char *metaname = "mine.type_t"; // associated with userdata of type type_t*
typedef struct {
@ -100,38 +107,43 @@ typedef struct {
int lib_a_f_4(type_t *t)
{
return t->a * t->b ;
return t->a * t->b ;
}
static int lua_lib_a_f_4(lua_State *L) {
type_t *t = (type_t *)luaL_checkudata(L, 1, metaname); // check argument type
lua_pushnumber(L, (lua_Number)lib_a_f_4(t));
return 1;
LUAMOD_API int lua_lib_a_f_4(lua_State *L) {
type_t *t = (type_t *)luaL_checkudata(L, 1, metaname); // check argument type
lua_pushnumber(L, (lua_Number)lib_a_f_4(t));
return 1;
}
static int lua_new_t(lua_State *L) { // get Lua to allocate an initialize a type_t*
int a = luaL_checkint(L, 1);
int b = luaL_checkint(L, 2);
type_t *t = (type_t *)lua_newuserdata(L, sizeof(*t));
luaL_getmetatable(L, metaname);
lua_setmetatable(L, -2);
t->a = a;
t->b = b;
return 1;
LUAMOD_API int lua_new_t(lua_State *L) { // get Lua to allocate an initialize a type_t*
int a = luaL_checkint(L, 1);
int b = luaL_checkint(L, 2);
type_t *t = (type_t *)lua_newuserdata(L, sizeof(*t));
luaL_getmetatable(L, metaname);
lua_setmetatable(L, -2);
t->a = a;
t->b = b;
return 1;
}
static const struct luaL_reg functions[] = {
{ "lib_a_f_4", lua_lib_a_f_4 },
{ "new_t", lua_new_t },
{ NULL, NULL }
static const luaL_Reg functionsTable[] = {
{ "lib_a_f_4", lua_lib_a_f_4 },
{ "new_t", lua_new_t },
{ NULL, NULL }
};
//http://www.swig.org/Doc1.3/Lua.html#Lua_nn13
//http://stackoverflow.com/questions/2521244/how-to-wrap-a-c-function-whose-parameters-are-pointer-to-structs-so-that-it-can
int mylib_open(lua_State *L) {
luaL_register(L, "mylib", functions);
luaL_newmetatable(L, metaname);
lua_pop(L, 1);
//luaL_newlib(L, functionsTable);
//lua_pop(L, 1);
return 1;
LUAMOD_API int luaopen_myLib(lua_State *L) {
luaL_register(L, "mylib", functionsTable);
luaL_newmetatable(L, metaname);
lua_pop(L, 1);
//luaL_newlib(L, functionsTable);
//lua_pop(L, 1);
return 1;
}
}

View File

@ -127,6 +127,7 @@ etkFloat_t quadDist(coord2D_ts pos1, coord2D_ts pos2);
#include <lua/lua.hpp>
int mylib_open(lua_State *L);
extern "C" {
LUAMOD_API int luaopen_myLib(lua_State *L);
}
#endif