[DEV] add luaWrapper

This commit is contained in:
Edouard DUPIN 2014-12-19 23:51:41 +01:00
parent 03fb0c4f8c
commit 5a98b86dea
17 changed files with 472 additions and 1 deletions

2
external/luaWrapper vendored

@ -1 +1 @@
Subproject commit 11bbc0e7a101c3473894cbf732ea361bec0b7609
Subproject commit 1c941a031b9382b3c98f00a0fcf39dc20c135a24

View File

@ -0,0 +1,71 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <etk/types.h>
#include <ewol/ewol.h>
#include <ewol/context/commandLine.h>
#include <appl/debug.h>
#include <appl/Windows.h>
#include <ewol/object/Object.h>
#include <ewol/widget/Manager.h>
#include <ewol/context/Context.h>
#include <lua/lua.h>
#include <lua/lualib.h>
#include <lua/lauxlib.h>
#include <ewolLua/ewolLua.h>
class MainApplication : public ewol::context::Application {
private:
lua_State* m_lua;
public:
bool init(ewol::Context& _context, size_t _initId) {
APPL_INFO("==> Init APPL (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")");
m_lua = luaL_newstate();
// TODO : Remove this : Move if in the windows properties
_context.setSize(vec2(800, 600));
luaL_openlibs(m_lua);
ewolLua::loadEwolLuaWrapper(m_lua);
// select internal data for font ...
_context.getFontDefault().setUseExternal(true);
_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
if (luaL_dostring(m_lua, "")) {
std::cout << lua_tostring(m_lua, -1) << std::endl;
}
std::shared_ptr<ewol::widget::Windows> basicWindows = appl::Windows::create();
// create the specific windows
_context.setWindows(basicWindows);
APPL_INFO("==> Init APPL (END)");
return true;
}
void unInit(ewol::Context& _context) {
APPL_INFO("==> Un-Init APPL (START)");
// nothing to do ...
lua_close(m_lua);
APPL_INFO("==> Un-Init APPL (END)");
}
};
/**
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
* @param std IO
* @return std IO
*/
int main(int _argc, const char *_argv[]) {
// second possibility
return ewol::run(new MainApplication(), _argc, _argv);
}

View File

@ -0,0 +1,14 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_MAIN_H__
#define __APPL_MAIN_H__
#endif

View File

@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <ewol/ewol.h>
#include <appl/debug.h>
#include <appl/Windows.h>
#include <ewol/widget/Label.h>
#undef __class__
#define __class__ "Windows"
appl::Windows::Windows() {
addObjectType("appl::Windows");
}
void appl::Windows::init() {
ewol::widget::Windows::init();
setTitle("example 001_HelloWord");
std::shared_ptr<ewol::widget::Label> tmpWidget = ewol::widget::Label::create();
if (tmpWidget == nullptr) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
tmpWidget->setLabel("Hello <font color=\"blue\">Word</font>");
tmpWidget->setExpand(bvec2(true,true));
setSubWidget(tmpWidget);
}
}

View File

@ -0,0 +1,25 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_WINDOWS_H__
#define __APPL_WINDOWS_H__
#include <ewol/widget/Windows.h>
namespace appl {
class Windows : public ewol::widget::Windows {
protected:
Windows();
void init();
public:
DECLARE_FACTORY(Windows);
};
};
#endif

View File

@ -0,0 +1,15 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
int32_t appl::getLogId() {
static int32_t g_val = etk::log::registerInstance("example");
return g_val;
}

View File

@ -0,0 +1,52 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_DEBUG_H__
#define __APPL_DEBUG_H__
#include <etk/log.h>
namespace appl {
int32_t getLogId();
};
// TODO : Review this problem of multiple intanciation of "std::stringbuf sb"
#define APPL_BASE(info,data) \
do { \
if (info <= etk::log::getLevel(appl::getLogId())) { \
std::stringbuf sb; \
std::ostream tmpStream(&sb); \
tmpStream << data; \
etk::log::logStream(appl::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \
} \
} while(0)
#define APPL_CRITICAL(data) APPL_BASE(1, data)
#define APPL_ERROR(data) APPL_BASE(2, data)
#define APPL_WARNING(data) APPL_BASE(3, data)
#ifdef DEBUG
#define APPL_INFO(data) APPL_BASE(4, data)
#define APPL_DEBUG(data) APPL_BASE(5, data)
#define APPL_VERBOSE(data) APPL_BASE(6, data)
#define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)
#else
#define APPL_INFO(data) do { } while(false)
#define APPL_DEBUG(data) do { } while(false)
#define APPL_VERBOSE(data) do { } while(false)
#define APPL_TODO(data) do { } while(false)
#endif
#define APPL_ASSERT(cond,data) \
do { \
if (!(cond)) { \
APPL_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)
#endif

32
sample/099_lua/lutin_099_lua.py Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
# optionnal : Describe in the "lutin.py --help"
def get_desc():
return "Tutorial 099 : lua example"
# Module creation instance (not optionnal)
def create(target):
# module name is '001_HelloWord' and type binary.
myModule = module.Module(__file__, '099_lua', 'BINARY')
# add the file to compile:
myModule.add_src_file([
'appl/Main.cpp',
'appl/debug.cpp',
'appl/Windows.cpp',
])
# add Library dependency name
myModule.add_module_depend(['ewolLua'])
# add application C flags
myModule.compile_flags_CC([
"-DPROJECT_NAME=\"\\\""+myModule.name+"\\\"\""])
# Add current include Path
myModule.add_path(tools.get_current_path(__file__))
# return the created module
return myModule

View File

@ -0,0 +1,14 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include "debug.h"
int32_t ewolLua::getLogId() {
static int32_t g_val = etk::log::registerInstance("ewolLua");
return g_val;
}

View File

@ -0,0 +1,52 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __EWOL_LUA_DEBUG_H__
#define __EWOL_LUA_DEBUG_H__
#include <etk/log.h>
namespace ewolLua {
int32_t getLogId();
};
// TODO : Review this problem of multiple intanciation of "std::stringbuf sb"
#define EWOLLUA_BASE(info,data) \
do { \
if (info <= etk::log::getLevel(ewolLua::getLogId())) { \
std::stringbuf sb; \
std::ostream tmpStream(&sb); \
tmpStream << data; \
etk::log::logStream(ewolLua::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \
} \
} while(0)
#define EWOLLUA_CRITICAL(data) EWOLLUA_BASE(1, data)
#define EWOLLUA_ERROR(data) EWOLLUA_BASE(2, data)
#define EWOLLUA_WARNING(data) EWOLLUA_BASE(3, data)
#ifdef DEBUG
#define EWOLLUA_INFO(data) EWOLLUA_BASE(4, data)
#define EWOLLUA_DEBUG(data) EWOLLUA_BASE(5, data)
#define EWOLLUA_VERBOSE(data) EWOLLUA_BASE(6, data)
#define EWOLLUA_TODO(data) EWOLLUA_BASE(4, "TODO : " << data)
#else
#define EWOLLUA_INFO(data) do { } while(false)
#define EWOLLUA_DEBUG(data) do { } while(false)
#define EWOLLUA_VERBOSE(data) do { } while(false)
#define EWOLLUA_TODO(data) do { } while(false)
#endif
#define EWOLLUA_ASSERT(cond,data) \
do { \
if (!(cond)) { \
EWOLLUA_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)
#endif

View File

@ -0,0 +1,18 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include "ewolLua.h"
#include "object.h"
#include "objectManager.h"
int32_t ewolLua::loadEwolLuaWrapper(lua_State* _L) {
loadObject(_L);
loadObjectManager(_L);
return 0;
}

View File

@ -0,0 +1,20 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __EWOL_LUA_H__
#define __EWOL_LUA_H__
#include <etk/types.h>
struct lua_State;
namespace ewolLua {
int32_t loadEwolLuaWrapper(lua_State* _L);
};
#endif

View File

@ -0,0 +1,35 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <ewol/object/Object.h>
#include <luaWrapper/luaWrapper.hpp>
#include "object.h"
#include "debug.h"
std::shared_ptr<ewol::Object> ewolObjectNew(lua_State *_L) {
const char* name = luaL_checkstring(_L, 1);
return ewol::Object::create(name);
}
static luaL_Reg s_metatable[] = {
//{ "getIdFunc", luaU_get<ewol::Object, int32_t, &ewol::Object::getId> },
//{ "NameFunc", luaU_getset<ewol::Object, std::string, &ewol::Object::getName, &ewol::Object::setName> },
{ "getObjectType", luaU_func(&ewol::Object::getObjectType) },
{ "getTypeDescription", luaU_func(&ewol::Object::getTypeDescription) },
{ "isTypeCompatible", luaU_func(&ewol::Object::isTypeCompatible) },
//{ "addObjectType", luaU_func(&ewol::Object::addObjectType) },
{ "getStatic", luaU_func(&ewol::Object::getStatic) },
{ NULL, NULL }
};
int32_t ewolLua::loadObject(lua_State* _L) {
luaW_register<ewol::Object>(_L, "ewol__Object", NULL, s_metatable, ewolObjectNew);
return 0;
}

View File

@ -0,0 +1,20 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __EWOL_LUA_OBJECT_H__
#define __EWOL_LUA_OBJECT_H__
#include <etk/types.h>
struct lua_State;
namespace ewolLua {
int32_t loadObject(lua_State* _L);
};
#endif

View File

@ -0,0 +1,17 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include "objectManager.h"
#include "debug.h"
int32_t ewolLua::loadObjectManager(lua_State* _L) {
return 0;
}

View File

@ -0,0 +1,20 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __EWOL_LUA_OBJECT_MANAGER_H__
#define __EWOL_LUA_OBJECT_MANAGER_H__
#include <etk/types.h>
struct lua_State;
namespace ewolLua {
int32_t loadObjectManager(lua_State* _L);
};
#endif

View File

@ -0,0 +1,33 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
import os
import lutinMultiprocess
def get_desc():
return "ewol lua Wrapper"
def get_license():
return "APACHE v2.0"
def create(target):
# module name is 'edn' and type binary.
myModule = module.Module(__file__, 'ewolLua', 'LIBRARY')
# add extra compilation flags :
myModule.add_extra_compile_flags()
# add the file to compile:
myModule.add_src_file([
'ewolLua/object.cpp',
'ewolLua/objectManager.cpp',
'ewolLua/ewolLua.cpp',
'ewolLua/debug.cpp',
])
# name of the dependency
myModule.add_module_depend(['ewol', 'luaWrapper'])
myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the
return myModule