First functionnal lua test with internal lib
This commit is contained in:
parent
038be3ef3e
commit
49e62a10d1
@ -26,6 +26,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Android \
|
|||||||
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
|
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
|
||||||
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||||
-DDATA_IN_APK \
|
-DDATA_IN_APK \
|
||||||
|
-DLUA_COMPAT_ALL \
|
||||||
-frtti
|
-frtti
|
||||||
else
|
else
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Android \
|
LOCAL_CFLAGS := -D__PLATFORM__Android \
|
||||||
@ -35,6 +36,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Android \
|
|||||||
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
|
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
|
||||||
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||||
-DDATA_IN_APK \
|
-DDATA_IN_APK \
|
||||||
|
-DLUA_COMPAT_ALL \
|
||||||
-frtti
|
-frtti
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
|||||||
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
|
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-debug\"" \
|
||||||
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||||
-DEWOL_USE_FREE_TYPE \
|
-DEWOL_USE_FREE_TYPE \
|
||||||
|
-DLUA_COMPAT_ALL \
|
||||||
-Wall
|
-Wall
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -35,6 +36,7 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
|||||||
-DEWOL_DEBUG_LEVEL=3 \
|
-DEWOL_DEBUG_LEVEL=3 \
|
||||||
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-release\"" \
|
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-release\"" \
|
||||||
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||||
|
-DLUA_COMPAT_ALL \
|
||||||
-DEWOL_USE_FREE_TYPE
|
-DEWOL_USE_FREE_TYPE
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
* @param ---
|
* @param ---
|
||||||
* @return ---
|
* @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_group = -1;
|
||||||
m_type = -1;
|
m_type = -1;
|
||||||
@ -88,8 +88,15 @@ etkFloat_t quadDist(coord2D_ts pos1, coord2D_ts pos2)
|
|||||||
|
|
||||||
#include <lua/lua.hpp>
|
#include <lua/lua.hpp>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include <lua/luaconf.h>
|
||||||
#include <lua/lauxlib.h>
|
#include <lua/lauxlib.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
|
||||||
const char *metaname = "mine.type_t"; // associated with userdata of type type_t*
|
const char *metaname = "mine.type_t"; // associated with userdata of type type_t*
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -100,38 +107,43 @@ typedef struct {
|
|||||||
|
|
||||||
int lib_a_f_4(type_t *t)
|
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) {
|
LUAMOD_API int lua_lib_a_f_4(lua_State *L) {
|
||||||
type_t *t = (type_t *)luaL_checkudata(L, 1, metaname); // check argument type
|
type_t *t = (type_t *)luaL_checkudata(L, 1, metaname); // check argument type
|
||||||
lua_pushnumber(L, (lua_Number)lib_a_f_4(t));
|
lua_pushnumber(L, (lua_Number)lib_a_f_4(t));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lua_new_t(lua_State *L) { // get Lua to allocate an initialize a type_t*
|
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 a = luaL_checkint(L, 1);
|
||||||
int b = luaL_checkint(L, 2);
|
int b = luaL_checkint(L, 2);
|
||||||
type_t *t = (type_t *)lua_newuserdata(L, sizeof(*t));
|
type_t *t = (type_t *)lua_newuserdata(L, sizeof(*t));
|
||||||
luaL_getmetatable(L, metaname);
|
luaL_getmetatable(L, metaname);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
t->a = a;
|
t->a = a;
|
||||||
t->b = b;
|
t->b = b;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct luaL_reg functions[] = {
|
static const luaL_Reg functionsTable[] = {
|
||||||
{ "lib_a_f_4", lua_lib_a_f_4 },
|
{ "lib_a_f_4", lua_lib_a_f_4 },
|
||||||
{ "new_t", lua_new_t },
|
{ "new_t", lua_new_t },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//http://www.swig.org/Doc1.3/Lua.html#Lua_nn13
|
//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
|
//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) {
|
LUAMOD_API int luaopen_myLib(lua_State *L) {
|
||||||
luaL_register(L, "mylib", functions);
|
luaL_register(L, "mylib", functionsTable);
|
||||||
luaL_newmetatable(L, metaname);
|
luaL_newmetatable(L, metaname);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
//luaL_newlib(L, functionsTable);
|
//luaL_newlib(L, functionsTable);
|
||||||
//lua_pop(L, 1);
|
//lua_pop(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ etkFloat_t quadDist(coord2D_ts pos1, coord2D_ts pos2);
|
|||||||
|
|
||||||
#include <lua/lua.hpp>
|
#include <lua/lua.hpp>
|
||||||
|
|
||||||
int mylib_open(lua_State *L);
|
extern "C" {
|
||||||
|
LUAMOD_API int luaopen_myLib(lua_State *L);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user