コード例 #1
0
	static void pushCCObject(CCObject *v, const char *t){
#if COCOS2D_VERSION >= 0x00030000
		luaStack()->pushObject(v, t);
#else
		luaStack()->pushCCObject(v, t);
#endif
	}
コード例 #2
0
	static bool pushLuaFunction(int nHandler){
		lua_State *l = luaStack()->getLuaState();
		toluafix_get_function_by_refid(l, nHandler);          /* stack: ... func */
		if(!lua_isfunction(l, -1)){
			CCLog("[LUA ERROR] function refid '%d' does not reference a Lua function", nHandler);
			lua_pop(l, 1);
			return false;
		}
		return true;
	}
コード例 #3
0
ファイル: LuaScript.cpp プロジェクト: TonyAlloa/miranda-dev
CLuaScript::~CLuaScript(void)
{
	CLuaStack luaStack(m_luaBridge);

LUA_CODE_CHUNK_ENTER(m_luaBridge)
	
	lua_rawgeti(state, LUA_REGISTRYINDEX, m_nThisRef);
	lua_pushnil(state);
	lua_rawseti(state, -2, 0);

LUA_CODE_CHUNK_LEAVE
}
コード例 #4
0
ファイル: LuaScript.cpp プロジェクト: TonyAlloa/miranda-dev
CLuaScript::CLuaScript(CLuaBridge & luaBridge) : m_luaBridge(luaBridge), m_nMethods(DEFAULT_INDEX_INITIALIZER), m_nThisRef(DEFAULT_INDEX_INITIALIZER), m_nArgs(DEFAULT_INDEX_INITIALIZER)
{
LUA_CODE_CHUNK_ENTER(luaBridge)

	lua_newtable(state);
	m_nThisRef = luaL_ref(state, LUA_REGISTRYINDEX);

	CLuaStack luaStack(luaBridge);
	lua_rawgeti(state, LUA_REGISTRYINDEX, m_nThisRef);
	lua_pushlightuserdata(state, reinterpret_cast<void*>(this));
	lua_rawseti(state, -2, 0);

LUA_CODE_CHUNK_LEAVE
}
コード例 #5
0
ファイル: LuaScript.cpp プロジェクト: TonyAlloa/miranda-dev
bool CLuaScript::ScriptHasFunction(const char * szFunction)
{
	CLuaStack luaStack(m_luaBridge);

	bool bRetVal = false;

LUA_CODE_CHUNK_ENTER(m_luaBridge)

	lua_rawgeti(state, LUA_REGISTRYINDEX, m_nThisRef);
	lua_pushstring(state, szFunction);
	lua_rawget(state, -2);
	lua_remove(state, -2);

	bRetVal = (lua_isfunction(state, -1) != FALSE);

LUA_CODE_CHUNK_LEAVE

	return bRetVal;
}
コード例 #6
0
ファイル: LuaScript.cpp プロジェクト: TonyAlloa/miranda-dev
int CLuaScript::RegisterFunction(const char *szFuncName)
{
	int nMethod = -1;

	CLuaStack luaStack(m_luaBridge);

LUA_CODE_CHUNK_ENTER(m_luaBridge)

	nMethod = ++m_nMethods;
	
	lua_rawgeti(state, LUA_REGISTRYINDEX, m_nThisRef);
	lua_pushstring(state, szFuncName);
	lua_pushnumber(state, (lua_Number)nMethod);
	lua_pushcclosure(state, CLuaScript::LuaCallback, 1);
	lua_settable(state, -3);

LUA_CODE_CHUNK_LEAVE

	return nMethod;
}
コード例 #7
0
	// Run lua function but do not get return value.
	// If (retInt) is true, try to return int and bool value, and auto finish function call.
	// Else, should manual call finishRunLuaFunction()
	static int runLuaFunction(int h, int numArgs, bool retInt = false){
		lua_State *l = luaStack()->getLuaState();
		if(pushLuaFunction(h)){                                         /* stack: ... arg1 arg2 ... func */
			if(numArgs > 0){
				lua_insert(l, -(numArgs + 1));                        /* stack: ... func arg1 arg2 ... */
			}
			int traceback = 0;
			lua_getglobal(l, "__G__TRACKBACK__");                     /* stack: ... func arg1 arg2 ... G */
			if (!lua_isfunction(l, -1)){
				lua_pop(l, 1);                                        /* stack: ... func arg1 arg2 ... */
			}else{
				traceback = -(numArgs + 2);
				lua_insert(l, traceback);                             /* stack: ... G func arg1 arg2 ... */
			}
			int error = 0;
			error = lua_pcall(l, numArgs, 1, traceback);              /* stack: ... ret */
			if (error){
				if (traceback == 0){
					CCLog("[LUA ERROR] %s", lua_tostring(l, - 1));    /* stack: ... error */
					lua_pop(l, 1); // remove error message from stack
				}
				return 0;
			}
			// get return value
			int ret = 1;
			if(retInt){
				if (lua_isnumber(l, -1)){
					ret = lua_tointeger(l, -1);
				}else if (lua_isboolean(l, -1)){
					ret = lua_toboolean(l, -1);
				}
				lua_pop(l, 1); // remove return value from stack
			}
			return ret;
		}else{
			lua_pop(l, numArgs); // remove args from stack
			return 0;
		}
	}
コード例 #8
0
	static void pushInt(int v){ luaStack()->pushInt(v);}
コード例 #9
0
	static void runString(const char *s){
		luaL_dostring(luaStack()->getLuaState(), s);
	}
コード例 #10
0
	static int runFunctionHandler(int hnd, int argNum, bool retInt = false){
		int r = 0;
		if(retInt){	r = runLuaFunction(hnd, argNum, true);}
		else{		luaStack()->executeFunctionByHandler(hnd, argNum);}
		return r;
	}
コード例 #11
0
	static void pushNil(){ luaStack()->pushNil();}
コード例 #12
0
	static void pushUsertype(void *v, const char *t){
		tolua_pushusertype(luaStack()->getLuaState(), v, t);
	}
コード例 #13
0
	static void pushString(const char *v){ luaStack()->pushString(v);}
コード例 #14
0
	static void pushBoolean(bool v){ luaStack()->pushBoolean(v);}
コード例 #15
0
	static void pushFloat(float v){ luaStack()->pushFloat(v);}