Exemplo n.º 1
0
	int pcall(lua_State *L, int nargs, int nresults)
	{
		pcall_callback_fun e = get_pcall_callback();
		int en = 0;
		if ( e )
		{
			int base = lua_gettop(L) - nargs;
			lua_pushcfunction(L, e);
			lua_insert(L, base);  // push pcall_callback under chunk and args
			en = base;
  		}
		int result = lua_pcall(L, nargs, nresults, en);
		if ( en )
			lua_remove(L, en);  // remove pcall_callback
		return result;
	}
Exemplo n.º 2
0
bool
CLuaVM::execute(){
    /*
If errfunc is 0, then the error message returned on the stack is exactly the original error message. Otherwise, errfunc is the stack index of an error handler function. (In the current implementation, this index cannot be a pseudo-index.) In case of runtime errors, this function will be called with the error message and its return value will be the message returned on the stack by lua_pcall.
*/

// will push the error function  each time
    //int result = luabind::detail::pcall(getVM(), 0, LUA_MULTRET);

    // Aller chercher la fct d'erreur dans detail::pcall
    int result = 0;
    //result = luabind::detail::pcall(getVM(), 0, LUA_MULTRET);

		pcall_callback_fun e = get_pcall_callback();
		int en = 0;
		if ( e )
		{
			int base = lua_gettop(_vm);
			lua_pushcfunction(_vm, e);
			lua_insert(_vm, base);  // push pcall_callback under chunk and args
			en = base;
  		}
  		//int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,int ctx, lua_CFunction k);
		result = lua_pcallk(_vm, 0, 0, en,0,0);
        if ( en )
			lua_remove(_vm, en);  // remove pcall_callback


    // If we are here, it means there has been an error so we unwind stack
    if(result != 0){

        //_LOG_ERROR << "Error happened while executing";
        setErrorDescription(result);

        return false;
    }

    return true;
}