lua:Change the print destination. game: all basics access between elements

This commit is contained in:
Edouard Dupin 2012-06-01 17:47:43 +02:00
parent 37a562812f
commit b6e02cc049
43 changed files with 449 additions and 208 deletions

View File

@ -72,3 +72,8 @@ void TOOLS_DisplayTime(void)
etk::cout << tmpdata ;
}
etk::logLevel_te g_requestedLevel = etk::LOG_LEVEL_ERROR;
void GeneralDebugSetLevel(etk::logLevel_te ccc) {
g_requestedLevel = ccc;
}

View File

@ -36,12 +36,17 @@ void TOOLS_DisplayTime(void);
#undef __class__
#define __class__ (NULL)
extern etk::logLevel_te g_requestedLevel;
void GeneralDebugSetLevel(etk::logLevel_te ccc);
#define ETK_DBG_COMMON(libName, info, data) do { \
etk::cout << etk::cstart << info; \
TOOLS_DisplayTime(); \
TOOLS_DisplayFuncName(__LINE__, __class__, __func__, libName); \
etk::cout << data; \
etk::cout <<etk::endl; \
if (info <= g_requestedLevel) { \
etk::cout << etk::cstart << info; \
TOOLS_DisplayTime(); \
TOOLS_DisplayFuncName(__LINE__, __class__, __func__, libName); \
etk::cout << data; \
etk::cout <<etk::endl; \
} \
}while(0)
#define ETK_CRITICAL(libName, data) ETK_DBG_COMMON(libName, etk::LOG_LEVEL_CRITICAL, data)
#define ETK_ERROR(libName, data) ETK_DBG_COMMON(libName, etk::LOG_LEVEL_ERROR, data)

View File

@ -93,16 +93,12 @@ namespace etk{
class CCout{
private:
bool hex;
logLevel_te m_requestedLevel;
bool m_writing;
char m_tmpChar[MAX_LOG_SIZE+1];
char tmp[MAX_LOG_SIZE_TMP];
pthread_mutex_t m_mutex;
public:
CCout(){
hex=false;
m_writing = true;
m_requestedLevel = LOG_LEVEL_ERROR;
memset(m_tmpChar, 0, (MAX_LOG_SIZE+1)*sizeof(char));
pthread_mutex_init(&m_mutex, NULL);
};
@ -111,181 +107,137 @@ namespace etk{
};
CCout& operator << (int t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%d", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%d", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (unsigned int t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%u", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%u", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
/*
CCout& operator << (uniChar_t t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%c", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%c", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
*/
CCout& operator << (long t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%ld", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%ld", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (long long t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%lld", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%lld", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (double t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%f", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%f", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (float t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%f", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%f", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (char * t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%s", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%s", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (const char * t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%s", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%s", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (char t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%c", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "%c", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (bool t) {
if (true == m_writing) {
if (t) {
strncat(m_tmpChar, "true", MAX_LOG_SIZE);
} else {
strncat(m_tmpChar, "false", MAX_LOG_SIZE);
}
if (t) {
strncat(m_tmpChar, "true", MAX_LOG_SIZE);
} else {
strncat(m_tmpChar, "false", MAX_LOG_SIZE);
}
return *this;
}
CCout& operator << (coord2D_ts t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "(%f,%f)", t.x, t.y);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "(%f,%f)", t.x, t.y);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (coord3D_ts t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "(%f,%f,%f)", t.x, t.y, t.z);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "(%f,%f,%f)", t.x, t.y, t.z);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (texCoord_ts t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "{%f,%f}", t.u, t.v);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "{%f,%f}", t.u, t.v);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (color_ts t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "#%02X%02X%02X%02X", t.red, t.green, t.blue, t.alpha);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "#%02X%02X%02X%02X", t.red, t.green, t.blue, t.alpha);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (clipping_ts t) {
if (true == m_writing) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "origin=(%f,%f) size=(%f,%f)", t.x, t.y, t.w, t.h);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
}
snprintf(tmp, MAX_LOG_SIZE_TMP, "origin=(%f,%f) size=(%f,%f)", t.x, t.y, t.w, t.h);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (CStart ccc) {
pthread_mutex_lock(&m_mutex);
return *this;
}
void SetLevel(logLevel_te ccc) {
m_requestedLevel = ccc;
}
CCout& operator << (logLevel_te ccc) {
if (ccc <= m_requestedLevel) {
m_writing = true;
} else {
m_writing = false;
}
if (true == m_writing) {
switch (ccc)
{
case LOG_LEVEL_CRITICAL:
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
strncat(m_tmpChar, "[C]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_ERROR:
strncat(m_tmpChar, ETK_BASH_COLOR_MAGENTA, MAX_LOG_SIZE);
strncat(m_tmpChar, "[E]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_WARNING:
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
strncat(m_tmpChar, "[W]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_INFO:
strncat(m_tmpChar, ETK_BASH_COLOR_CYAN, MAX_LOG_SIZE);
strncat(m_tmpChar, "[I]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_DEBUG:
strncat(m_tmpChar, ETK_BASH_COLOR_YELLOW, MAX_LOG_SIZE);
strncat(m_tmpChar, "[D]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_VERBOSE:
strncat(m_tmpChar, ETK_BASH_COLOR_WHITE, MAX_LOG_SIZE);
strncat(m_tmpChar, "[V]", MAX_LOG_SIZE);
break;
default:
strncat(m_tmpChar, "[?]", MAX_LOG_SIZE);
break;
}
switch (ccc)
{
case LOG_LEVEL_CRITICAL:
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
strncat(m_tmpChar, "[C]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_ERROR:
strncat(m_tmpChar, ETK_BASH_COLOR_MAGENTA, MAX_LOG_SIZE);
strncat(m_tmpChar, "[E]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_WARNING:
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
strncat(m_tmpChar, "[W]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_INFO:
strncat(m_tmpChar, ETK_BASH_COLOR_CYAN, MAX_LOG_SIZE);
strncat(m_tmpChar, "[I]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_DEBUG:
strncat(m_tmpChar, ETK_BASH_COLOR_YELLOW, MAX_LOG_SIZE);
strncat(m_tmpChar, "[D]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_VERBOSE:
strncat(m_tmpChar, ETK_BASH_COLOR_WHITE, MAX_LOG_SIZE);
strncat(m_tmpChar, "[V]", MAX_LOG_SIZE);
break;
default:
strncat(m_tmpChar, "[?]", MAX_LOG_SIZE);
break;
}
return *this;
}
CCout& operator << (etk::CEndl t) {
if (true == m_writing) {
strncat(m_tmpChar, ETK_BASH_COLOR_NORMAL, MAX_LOG_SIZE);
strncat(m_tmpChar, "\n", MAX_LOG_SIZE);
m_tmpChar[MAX_LOG_SIZE] = '\0';
strncat(m_tmpChar, ETK_BASH_COLOR_NORMAL, MAX_LOG_SIZE);
strncat(m_tmpChar, "\n", MAX_LOG_SIZE);
m_tmpChar[MAX_LOG_SIZE] = '\0';
#if defined(__PLATFORM__Android)
LOGI("%s", m_tmpChar);
LOGI("%s", m_tmpChar);
#else
printf("%s", m_tmpChar);
printf("%s", m_tmpChar);
#endif
memset(m_tmpChar, 0, (MAX_LOG_SIZE+1)*sizeof(char));
}
memset(m_tmpChar, 0, (MAX_LOG_SIZE+1)*sizeof(char));
pthread_mutex_unlock(&m_mutex);
return *this;
}

View File

@ -83,7 +83,8 @@ namespace ewol {
int32_t PowerGet(void) { return m_power; };
void PowerSet(int32_t state) { m_power = state; };
int32_t GetType(void) { return m_type; };
int32_t GetType(void) { return m_type; }; // DEPRECATED ...
int32_t TypeGet(void) { return m_type; };
int32_t GroupGet(void) { return m_group; };
void GroupSet(int32_t state) { m_group = state; };

View File

@ -38,6 +38,101 @@ static etk::VectorType<ewol::Sprite*> * tmpSprite = NULL;
static etk::VectorType<ewol::Sprite*> * tmpEffects = NULL;
static ewol::SceneElement * tmpScene = NULL;
template <typename T> int index(lua_State* L);
template <> int index<bool>(lua_State* L)
{
bool* ptr = (bool*)lua_touserdata(L, 1);
lua_pushboolean(L, *ptr ? 1 : 0);
return 1;
}
template <> int index<float>(lua_State* L)
{
float* ptr = (float*)lua_touserdata(L, 1);
lua_pushnumber(L, *ptr);
return 1;
}
template <typename T> int newindex(lua_State* L);
template <> int newindex<bool>(lua_State* L)
{
bool* ptr = (bool*)lua_touserdata(L, 1);
*ptr = lua_toboolean(L, 3)!=0;
return 0;
}
template <> int newindex<float>(lua_State* L)
{
float* ptr = (float*)lua_touserdata(L, 1);
if (!lua_isnumber(L, 3)) {
return luaL_error(L, "new value must be a number");
}
*ptr = (float)lua_tonumber(L, 3);
return 1;
}
template <typename T> class LuaValue
{
private:
lua_State* L;
etk::UString name;
T* ptr;
public:
LuaValue(lua_State* _L, etk::UString _name)
: L(_L), name(_name), ptr(0)
{
ptr = (T*)lua_newuserdata(L, sizeof(T));
*ptr = T();
lua_createtable(L, 0, 2);
lua_pushcfunction(L, index<T>);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, newindex<T>);
lua_setfield(L, -2, "__newindex");
lua_setmetatable(L, -2);
lua_setglobal(L, name.Utf8Data());
}
virtual ~LuaValue(void)
{
lua_pushnil(L);
lua_setglobal(L, name.Utf8Data());
ptr = 0;
L = 0;
}
LuaValue<T>& operator=(const T& value) { *ptr = value; return *this; }
operator T() { return *ptr; }
};
/*
template <> int lua_Set<etkFloat_t>(lua_State* L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
etkFloat_t value = luaL_checknumber(L, 1);
tmpObj->AngleSet(value);
// return number of parameters
return 1;
}
template <> int lua_Get<etkFloat_t>(lua_State* L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
etkFloat_t value = tmpObj->AngleGet();
lua_pushnumber(L, value );
// return number of parameters
return 1;
}
*/
LUAMOD_API int lua_GetPos(lua_State *L)
{
@ -153,6 +248,33 @@ LUAMOD_API int lua_SetAngle(lua_State *L)
return 1;
}
LUAMOD_API int lua_GetSize(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
etkFloat_t value = tmpObj->SizeGet();
lua_pushnumber(L, value );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetSize(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
etkFloat_t value = luaL_checknumber(L, 1);
tmpObj->SizeSet(value);
// return number of parameters
return 1;
}
LUAMOD_API int lua_SpriteLoad(lua_State *L)
{
//LUA : int SpriteLoad("fileName", maxSize); => -1 in error ...
@ -267,6 +389,30 @@ LUAMOD_API int lua_ElementSetPos(lua_State *L)
return 0;
}
LUAMOD_API int lua_ElementGetPos(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene) {
EWOL_ERROR("ploppp ");
lua_pushnumber(L, (lua_Number)0 );
lua_pushnumber(L, (lua_Number)0 );
return 2;
}
int32_t idElement = luaL_checkint(L, 1);
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
coord2D_ts tmpPos = tmpElem->PositionGet();
lua_pushnumber(L, (lua_Number)tmpPos.x );
lua_pushnumber(L, (lua_Number)tmpPos.y );
} else {
lua_pushnumber(L, (lua_Number)0.0 );
lua_pushnumber(L, (lua_Number)0.0 );
EWOL_ERROR("Get element unique ID : " << idElement);
}
// return number of parameters
return 2;
}
LUAMOD_API int lua_ElementSetPower(lua_State *L)
{
//LUA : ElementSetPower(newElementId, 1);
@ -301,6 +447,100 @@ LUAMOD_API int lua_ElementSetAngle(lua_State *L)
return 1;
}
LUAMOD_API int lua_GetNearestEnemy(lua_State *L)
{
//LUA : int GetNearestEnemy()
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushinteger(L, 0 );
return 1;
}
uint32_t elementId = tmpScene->GetNearestEnemy(tmpObj->PositionGet(), tmpObj->GroupGet());
if (0==elementId) {
EWOL_ERROR("Error getting enemy ...");
}
lua_pushinteger(L, elementId );
// return number of parameters
return 1;
}
LUAMOD_API int lua_ElmentExisted(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene) {
EWOL_ERROR("NULL obj...");
lua_pushboolean(L, false );
return 1;
}
int32_t idElement = luaL_checkint(L, 1);
if (0 != idElement) {
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
lua_pushboolean(L, true );
} else {
lua_pushboolean(L, false );
}
} else {
lua_pushboolean(L, false );
}
// return number of parameters
return 1;
}
LUAMOD_API int lua_HaveImpact(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushboolean(L, false );
return 1;
}
// TODO : Remove this when find an other way do do it ...
ewol::GameElementLua * ttmpObj = tmpObj;
etk::VectorType<ewol::Sprite*> * ttmpSprite = tmpSprite;
etk::VectorType<ewol::Sprite*> * ttmpEffects = tmpEffects;
ewol::SceneElement * ttmpScene = tmpScene;
bool result = tmpScene->HaveImpact(tmpObj->GroupGet(), tmpObj->TypeGet(), tmpObj->PositionGet(), tmpObj->SizeGet());
tmpObj = ttmpObj;
tmpSprite = ttmpSprite;
tmpEffects = ttmpEffects;
tmpScene = ttmpScene;
lua_pushboolean(L, result );
// return number of parameters
return 1;
}
LUAMOD_API int lua_Explosion(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
return 0;
}
// TODO : Remove this when find an other way do do it ...
ewol::GameElementLua * ttmpObj = tmpObj;
etk::VectorType<ewol::Sprite*> * ttmpSprite = tmpSprite;
etk::VectorType<ewol::Sprite*> * ttmpEffects = tmpEffects;
ewol::SceneElement * ttmpScene = tmpScene;
tmpScene->Explosion(tmpObj->GroupGet(), tmpObj->TypeGet(), tmpObj->PositionGet(), 0.01, tmpObj->PowerGet());
tmpObj = ttmpObj;
tmpSprite = ttmpSprite;
tmpEffects = ttmpEffects;
tmpScene = ttmpScene;
// return number of parameters
return 0;
}
static const luaL_Reg functionsTable[] = {
// local element section
{ "GetPos", lua_GetPos },
@ -308,14 +548,21 @@ static const luaL_Reg functionsTable[] = {
{ "GetSpeed", lua_GetSpeed },
{ "SetSpeed", lua_SetSpeed },
{ "GetAngle", lua_GetAngle },
{ "SetAngle", lua_GetAngle },
{ "SetAngle", lua_SetAngle },
{ "GetSize", lua_GetSize },
{ "SetSize", lua_SetSize },
{ "GetPower", lua_GetPower },
{ "SetPower", lua_GetPower },
{ "SetPower", lua_SetPower },
// other element section
{ "ElementAdd", lua_ElementAdd },
{ "ElementExisted", lua_ElmentExisted },
{ "ElementSetPos", lua_ElementSetPos },
{ "ElementGetPos", lua_ElementGetPos },
{ "ElementSetPower", lua_ElementSetPower },
{ "ElementSetAngle", lua_ElementSetAngle },
{ "GetNearestEnemy", lua_GetNearestEnemy },
{ "HaveImpact", lua_HaveImpact },
{ "Explosion", lua_Explosion },
// Sprite section
{ "SpriteLoad", lua_SpriteLoad },
{ "SpriteUnLoad", lua_SpriteUnLoad },
@ -341,6 +588,7 @@ ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::USt
ewol::GameElement(sceneElement, tmpName),
m_luaState(NULL)
{
m_group = group;
tmpObj = this;
tmpScene = &m_sceneElement;
etk::File fileElement(tmpName, etk::FILE_TYPE_DATA);
@ -355,7 +603,12 @@ ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::USt
luaL_openlibs(m_luaState);
// open internal specific elements ...
luaopen_myLib(m_luaState);
/*
LuaValue<bool> *myBool = new LuaValue<bool>(m_luaState, "m_testBool");
LuaValue<float> *myValue = new LuaValue<float>(m_luaState, "m_testFloat");
*myBool = false;
*myValue = 18;
*/
int32_t fileSize = fileElement.Size();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << fileElement);
@ -404,6 +657,9 @@ ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::USt
return;
}
}
/*
EWOL_INFO("retreave element : " << *myValue << " and : " << *myBool);
*/
tmpObj = NULL;
tmpScene = NULL;
}
@ -494,14 +750,26 @@ void ewol::GameElementLua::Draw(etk::VectorType<ewol::Sprite*> & listOfSprite, e
bool ewol::GameElementLua::HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size)
{
//HaveImpact(group, type, posX, posY, size)
// todo set a flag that permit lua to direct control of this ...
// check if it was in the same group
if (group == m_group) {
return false;
}
etkFloat_t quadDistance = quadDist(m_position, position);
etkFloat_t radiusElement = m_size * m_size;
if (radiusElement < quadDistance) {
//distance is greten than expected
return false;
}
//HaveImpact(group, type, posX, posY, size, quadDistance)
tmpObj = this;
bool retVal = false;
bool retVal = true;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "Process");
lua_getglobal(m_luaState, "HaveImpact");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_WARNING("LUA: Not Find 'Process' function ");
EWOL_VERBOSE("LUA: Not Find 'HaveImpact' function ");
lua_pop(m_luaState,1);
} else {
lua_pushnumber(m_luaState, group);
@ -509,8 +777,9 @@ bool ewol::GameElementLua::HaveImpact(int32_t group, int32_t type, coord2D_ts po
lua_pushnumber(m_luaState, position.x);
lua_pushnumber(m_luaState, position.y);
lua_pushnumber(m_luaState, size);
// do the call (5 arguments, 1 result)
if (lua_pcall(m_luaState, 5, 1, 0) != 0) {
lua_pushnumber(m_luaState, quadDistance);
// do the call (6 arguments, 1 result)
if (lua_pcall(m_luaState, 6, 1, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Process':" << lua_tostring(m_luaState, -1));
} else {
// retrieve result
@ -534,9 +803,9 @@ void ewol::GameElementLua::Explosion(int32_t group, int32_t type, coord2D_ts pos
tmpObj = this;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "Process");
lua_getglobal(m_luaState, "Explosion");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_WARNING("LUA: Not Find 'Process' function ");
EWOL_VERBOSE("LUA: Not Find 'Explosion' function ");
lua_pop(m_luaState,1);
} else {
lua_pushnumber(m_luaState, group);
@ -545,9 +814,11 @@ void ewol::GameElementLua::Explosion(int32_t group, int32_t type, coord2D_ts pos
lua_pushnumber(m_luaState, position.y);
lua_pushnumber(m_luaState, pxAtenuation);
lua_pushnumber(m_luaState, power);
// do the call (6 arguments, 0 result)
if (lua_pcall(m_luaState, 6, 0, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Process':" << lua_tostring(m_luaState, -1));
etkFloat_t quadDistance = quadDist(m_position, position);
lua_pushnumber(m_luaState, quadDistance);
// do the call (7 arguments, 0 result)
if (lua_pcall(m_luaState, 7, 0, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Explosion':" << lua_tostring(m_luaState, -1));
}
}
}

View File

@ -114,6 +114,10 @@ uint32_t ewol::SceneElement::GetNearestEnemy(coord2D_ts position, int32_t groupI
uint32_t result = 0;
etkFloat_t lastQuadDistance = 9999999999999999.0;
int32_t jjj=0;
if (groupId <0 || groupId >= MAX_GROUP_NUMBER) {
EWOL_ERROR("incorect group number : " << groupId);
return 0;
}
while (groupEnemy[groupId][jjj] != -1) {
for (int32_t iii=0; iii<listAnimatedElements[groupEnemy[groupId][jjj]].Size(); iii++) {
if (NULL != listAnimatedElements[groupEnemy[groupId][jjj]][iii]) {

View File

@ -128,6 +128,7 @@ int32_t offsetMoveClickedDouble = 20000;
#define PTHREAD_GUI_LOCK_MULTITHREAD
#ifdef PTHREAD_GUI_LOCK_MULTITHREAD
static pthread_mutex_t l_mutex;
#if 1
#define GUI_LOCK() do { \
/*EWOL_DEBUG("GUI-Lock");*/ \
pthread_mutex_lock(&l_mutex); \
@ -138,6 +139,12 @@ int32_t offsetMoveClickedDouble = 20000;
pthread_mutex_unlock(&l_mutex); \
/*EWOL_DEBUG("GUI-UnLock (done)");*/ \
}while(0)
#else
#define GUI_LOCK() do { \
}while(0)
#define GUI_UNLOCK() do { \
}while(0)
#endif
#else
#define GUI_LOCK() XLockDisplay(m_display)
#define GUI_UNLOCK() XUnlockDisplay(m_display)
@ -1300,19 +1307,19 @@ int main(int argc, char *argv[])
for( int32_t i=1 ; i<argc; i++) {
EWOL_INFO("CmdLine : \"" << argv[i] << "\"" );
if (0==strncmp("-l0", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_NONE);
GeneralDebugSetLevel(etk::LOG_LEVEL_NONE);
} else if (0==strncmp("-l1", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_CRITICAL);
GeneralDebugSetLevel(etk::LOG_LEVEL_CRITICAL);
} else if (0==strncmp("-l2", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_ERROR);
GeneralDebugSetLevel(etk::LOG_LEVEL_ERROR);
} else if (0==strncmp("-l3", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_WARNING);
GeneralDebugSetLevel(etk::LOG_LEVEL_WARNING);
} else if (0==strncmp("-l4", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_INFO);
GeneralDebugSetLevel(etk::LOG_LEVEL_INFO);
} else if (0==strncmp("-l5", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_DEBUG);
GeneralDebugSetLevel(etk::LOG_LEVEL_DEBUG);
} else if (0==strncmp("-l6", argv[i], 256)) {
etk::cout.SetLevel(etk::LOG_LEVEL_VERBOSE);
GeneralDebugSetLevel(etk::LOG_LEVEL_VERBOSE);
} else {
etk::UString* tmpString = new etk::UString(argv[i]);
if (NULL != tmpString) {

View File

@ -6,7 +6,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := lua
# name of the dependency
LOCAL_STATIC_LIBRARIES :=
LOCAL_STATIC_LIBRARIES := etk
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/lua/

View File

@ -6,7 +6,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := lua
# name of the dependency
LOCAL_STATIC_LIBRARIES :=
LOCAL_STATIC_LIBRARIES := etk
LOCAL_C_INCLUDES := -I$(LOCAL_PATH) -I$(LOCAL_PATH)/lua/

View File

@ -1,35 +1,35 @@
FILE_LIST = lua/lapi.c \
lua/lauxlib.c \
lua/lbaselib.c \
lua/lbitlib.c \
lua/lcode.c \
lua/lcorolib.c \
lua/lctype.c \
lua/ldblib.c \
lua/ldebug.c \
lua/ldo.c \
lua/ldump.c \
lua/lfunc.c \
lua/lgc.c \
lua/linit.c \
lua/liolib.c \
lua/llex.c \
lua/lmathlib.c \
lua/lmem.c \
lua/loadlib.c \
lua/lobject.c \
lua/lopcodes.c \
lua/loslib.c \
lua/lparser.c \
lua/lstate.c \
lua/lstring.c \
lua/lstrlib.c \
lua/ltable.c \
lua/ltablib.c \
lua/ltm.c \
lua/lundump.c \
lua/lvm.c \
lua/lzio.c
FILE_LIST = lua/lapi.cpp \
lua/lauxlib.cpp \
lua/lbaselib.cpp \
lua/lbitlib.cpp \
lua/lcode.cpp \
lua/lcorolib.cpp \
lua/lctype.cpp \
lua/ldblib.cpp \
lua/ldebug.cpp \
lua/ldo.cpp \
lua/ldump.cpp \
lua/lfunc.cpp \
lua/lgc.cpp \
lua/linit.cpp \
lua/liolib.cpp \
lua/llex.cpp \
lua/lmathlib.cpp \
lua/lmem.cpp \
lua/loadlib.cpp \
lua/lobject.cpp \
lua/lopcodes.cpp \
lua/loslib.cpp \
lua/lparser.cpp \
lua/lstate.cpp \
lua/lstring.cpp \
lua/lstrlib.cpp \
lua/ltable.cpp \
lua/ltablib.cpp \
lua/ltm.cpp \
lua/lundump.cpp \
lua/lvm.cpp \
lua/lzio.cpp

View File

@ -18,11 +18,14 @@
#include "lauxlib.h"
#include "lualib.h"
#include <etk/Debug.h>
static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
int i;
#if 0
// oudside etk :
lua_getglobal(L, "tostring");
for (i=1; i<=n; i++) {
const char *s;
@ -39,6 +42,27 @@ static int luaB_print (lua_State *L) {
lua_pop(L, 1); /* pop result */
}
luai_writeline();
#else
lua_getglobal(L, "tostring");
etk::cout << etk::cstart << etk::LOG_LEVEL_INFO;
TOOLS_DisplayTime();
TOOLS_DisplayFuncName(__LINE__, __class__, __func__, "luaFile ");
for (i=1; i<=n; i++) {
const char *s;
size_t l;
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
s = lua_tolstring(L, -1, &l); /* get result */
if (s == NULL) {
return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
}
if (i>1) etk::cout << "\t";
etk::cout << s;
lua_pop(L, 1); /* pop result */
}
etk::cout <<etk::endl;
#endif
return 0;
}

View File

@ -40,36 +40,11 @@
** =======================================================
*/
/*
** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By
** default, Lua handles errors with exceptions when compiling as
** C++ code, with _longjmp/_setjmp when asked to use them, and with
** longjmp/setjmp otherwise.
*/
#if !defined(LUAI_THROW)
#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
/* C++ exceptions */
#define LUAI_THROW(L,c) throw(c)
#define LUAI_TRY(L,c,a) \
try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
#define luai_jmpbuf int /* dummy variable */
#elif defined(LUA_USE_ULONGJMP)
/* in Unix, try _longjmp/_setjmp (more efficient) */
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
#define luai_jmpbuf jmp_buf
#else
/* default handling with long jumps */
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
#define luai_jmpbuf jmp_buf
#endif
#endif
@ -128,9 +103,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
lj.status = LUA_OK;
lj.previous = L->errorJmp; /* chain new error handler */
L->errorJmp = &lj;
LUAI_TRY(L, &lj,
(*f)(L, ud);
);
LUAI_TRY(L, &lj, (*f)(L, ud); );
L->errorJmp = lj.previous; /* restore old error handler */
L->nCcalls = oldnCcalls;
return lj.status;

View File

@ -2,8 +2,7 @@
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
}