Ejemplo n.º 1
0
        LuaBindingNamespace::self_type& LuaBindingNamespace::addConst(const char* const_name, const char* n, size_t s) {
            lua_State* state = getLuaState();
            lua_pushstring(state, const_name);
            lua_pushlstring(state, n, s);
            lua_settable(state, getNamespaceTable());

            return *this;
        }
Ejemplo n.º 2
0
lua_State * LuaEngineUtils::getLuaStateByFunName(const char *luaFileName, const char *funName)
{
    if(isOpenLua(luaFileName)){
        lua_State* ls = getLuaState();
        lua_getglobal(ls, funName);
        return ls;
    }
    CCLOG("Open Lua Error  getLuaStateByFunName: file = %s, fun = %s", luaFileName, funName);
    return NULL;
}
Ejemplo n.º 3
0
bool LuaEngineUtils::callLuaFuncReturnBool(const char *luaFileName, const char *funcName, const char *format, ...)
{
    va_list args;
    va_start(args, format);
    bool b = callLuaFunc(luaFileName, funcName, format, args);
    va_end(args);
    if(b){
        lua_State *ls = getLuaState();
        if(lua_isboolean(ls, -1)){
            return lua_toboolean(ls, -1);
        }
    }
    return false;
}
Ejemplo n.º 4
0
const char * LuaEngineUtils::callLuaFuncReturnChar(const char *luaFileName, const char *funcName, const char *format, ...)
{
    va_list args;
    va_start(args, format);
    bool b = callLuaFunc(luaFileName, funcName, format, args);
    va_end(args);
    if(b){
        lua_State *ls = getLuaState();
        if(lua_isstring(ls, -1)){
            return lua_tostring(ls, -1);
        }
    }
    return NULL;
}
Ejemplo n.º 5
0
int LuaEngineUtils::callLuaFuncReturnInt(const char *luaFileName, const char *funcName, const char *format, ...)
{
    va_list args;
    va_start(args, format);
    bool b = callLuaFunc(luaFileName, funcName, format, args);
    va_end(args);
    if(b){
        lua_State *ls = getLuaState();
        if(lua_isnumber(ls, -1)){
            return lua_tonumber(ls, -1);
        }
    }
    return 0;
}
Ejemplo n.º 6
0
void InAppPurchaseDelegate::onPurchaseFailed( const char* desc )
{
	if(m_ScriptHandler)
	{
		auto stack = LuaEngine::getInstance()->getLuaStack();
		auto state = stack->getLuaState();

		if(state)
		{
			stack->pushInt(IAP_EVENT_PURCHASE_FAILED);
			stack->pushString(desc);
			stack->executeFunctionByHandler(m_ScriptHandler,2);
		}
	}
}
Ejemplo n.º 7
0
void InAppPurchaseDelegate::onQueryProductFinish()
{
	m_bQuery = false;
	if(m_ScriptHandler)
	{
		auto stack = LuaEngine::getInstance()->getLuaStack();
		auto state = stack->getLuaState();

		if(state)
		{
			stack->pushInt(IAP_EVENT_QUERY_FINISH);
			stack->executeFunctionByHandler(m_ScriptHandler,1);
		}
	}
}
Ejemplo n.º 8
0
const char* LuaEngineUtils::getLuaVarString(const char *luaFileName, const char *varName)
{
    if(isOpenLua(luaFileName)){
        lua_State* ls = getLuaState();
        lua_settop(ls, 0);
        lua_getglobal(ls, varName);
        int statesCode = lua_isstring(ls, 1);
        if(statesCode != 1){
            CCLOG("Read Var String error = %d", statesCode);
            return NULL;
        }
        const char* str = lua_tostring(ls, 1);
        lua_pop(ls, 1);
        return str;
        
    }
    return NULL;
}
Ejemplo n.º 9
0
const char* LuaEngineUtils::getLuaVarTableProp(const char *luaFileName, const char *varName, const char *key)
{
    if(isOpenLua(luaFileName)){
        lua_State* ls = getLuaState();
        lua_getglobal(ls, varName);
        int statusCode = lua_istable(ls, -1);
        if(statusCode != 1){
            CCLOG("Read Var Table error = %d", statusCode);
            return NULL;
        }
        lua_pushstring(ls, key);
        lua_gettable(ls, -2);
        const char* str = lua_tostring(ls, -1);
        lua_pop(ls, -1);
        return str;
    }
    return NULL;
}
Ejemplo n.º 10
0
void InAppPurchaseDelegate::onPurchaseFinish(void* content)
{
	if(m_ScriptHandler)
	{
		auto stack = LuaEngine::getInstance()->getLuaStack();
		auto state = stack->getLuaState();

		if(state)
		{
			const char* str = (const char*)content;
			stack->pushInt(IAP_EVENT_PURCHASE_FINISH);
            if (str != NULL ) {
                stack->pushString(str);
            }else
                stack->pushNil();
			stack->executeFunctionByHandler(m_ScriptHandler,2);
		}
	}
}
Ejemplo n.º 11
0
const char* LuaEngineUtils::getLuaVarTable(const char *luaFileName, const char *varName)
{
    if(isOpenLua(luaFileName)){
        lua_State* ls = getLuaState();
        lua_getglobal(ls, varName);
        int it = lua_gettop(ls);
        lua_pushnil(ls);
        string result = "";
        while (lua_next(ls, it)) {
            string key = lua_tostring(ls, -2);
            string value = lua_tostring(ls, -1);
            result += key + ":" + value + "\t";
            lua_pop(ls, 1);
        }
        lua_pop(ls, 1);
        return result.c_str();
    }
    return NULL;
}
static LuaStack * initExecParam(Node *node, int phase)
{
    if (!node) return nullptr;
    int  id = node->_luaID;
    if (id<1)
    {
        return nullptr;
    }
    
    LuaEngine* engine = LuaEngine::getInstance();
    auto stack = engine->getLuaStack();
    stack->clean();
    
    auto L = stack->getLuaState();
    luaL_getmetatable(L, "cc.Node");                             /* stack: mt */
    lua_pushliteral(L, "EventDispatcher");
    lua_rawget(L, -2);                                           /* stack: mt func */
    lua_pushstring(L, "tolua_ubox");                             /* stack: mt func key */
    lua_rawget(L, -3);                                           /* stack: mt func ubox */
    if (lua_isnil(L, -1))
    {
        // use global ubox
        lua_pop(L, 1);                                              /* stack: mt func */
        lua_pushstring(L, "tolua_ubox");                            /* stack: mt func key */
        lua_rawget(L, LUA_REGISTRYINDEX);                           /* stack: mt func ubox */
    };
    lua_pushlightuserdata(L, node);                                 /* stack: mt func ubox ptr */
    lua_rawget(L,-2);                                               /* stack: mt func ubox ud */
    if (lua_isnil(L, -1))
    {
        stack->clean();
        return nullptr;
    }
    
    int etype = (phase == NODE_TOUCH_CAPTURING_PHASE) ? NODE_TOUCH_CAPTURE_EVENT : NODE_TOUCH_EVENT;
    lua_pushnumber(L, etype);                                       /* stack: mt func ubox ud etype */
    lua_remove(L, -3);                                              /* stack: mt func ud etype */

    return stack;
}
Ejemplo n.º 13
0
const bool CtrlrLuaMethod::setCodeInternal(const String &newMethodCode)
{
	bool compileRet			= owner.getOwner().runCode (newMethodCode);
	errorString.clear();
	errorString.append ("Compile: "+getName()+" - ", out, Colours::black);

	String error;

	if (compileRet && getName() != String::empty)
	{
		try
		{
			setObject ( (luabind::object)luabind::globals (getLuaState()) [(const char *)getName().toUTF8()] );
		}
		catch (const luabind::error &e)
		{
			error = String(e.what());
		}
	}
	else if (compileRet == false)
	{
		error = owner.getOwner().getLastError();
	}

	if (compileRet)
	{
		errorString.append ("OK\n", out.withStyle(Font::bold), Colours::black);
	}
	else
	{
		errorString.append ("FAILED\n", out.withStyle(Font::bold), Colours::darkred);
		errorString.append (error+"\n", out, Colours::darkred);
	}

	setValid(compileRet);

	return (compileRet);
}