Exemple #1
0
bool csp::OpLua::CallLua( lua::LuaStack& stack, const char* functionName, int numArgs, int numRets )
{
	CORE_ASSERT( m_self != lua::LUA_NO_REF );
	stack.PushRegistryReferenced( m_self );

	lua::LuaStackValue top = stack.GetTopValue();
	CORE_ASSERT( top.IsTable() );

	stack.GetField( top, functionName );

	if ( !stack.GetTopValue().IsFunction() )
	{
		stack.Pop( numArgs + 2 );
		return false;
	}

	// stack at this point: arg1, arg2, argN, self, function

	stack.Insert( -numArgs-2 );
	stack.Insert( -numArgs-1 );

	// stack at this point: function, self, arg1, arg2, argN

	lua::LuaState luaState( stack.InternalState() );
	lua::Return::Enum result = luaState.Call( 1+numArgs, numRets );
	return result == lua::Return::OK;
}
Exemple #2
0
    int GenericMeta::ToString(lua_State* state)
    {
        // Create the State needed for calls to C++ code
        std::shared_ptr<State> luaState(new State(state));

        lua_getmetatable(state, -1);
        Table meta = Stack<Table>::Pop(luaState);

        std::string str = "userdata: " + meta.Get<std::string>("__name");
        Stack<std::string>::Push(luaState, str);

        return 1;
    }
Exemple #3
0
int moEffect::ScriptCalling(moLuaVirtualMachine& vm, int iFunctionNumber)
{

    switch ( iFunctionNumber - m_iMethodBase )
    {
    case 0:
        ResetScriptCalling();
        return luaPlay(vm);
    case 1:
        ResetScriptCalling();
        return luaPause(vm);
    case 2:
        ResetScriptCalling();
        return luaStop(vm);
    case 3:
        ResetScriptCalling();
        return luaState(vm);

    case 4:
        ResetScriptCalling();
        return luaEnable(vm);
    case 5:
        ResetScriptCalling();
        return luaDisable(vm);



    case 6:
        ResetScriptCalling();
        return luaSetTicks(vm);
    case 7:
        ResetScriptCalling();
        return luaGetTicks(vm);

    ///for this Effect
    case 8:
        ResetScriptCalling();
        return luaGetEffectState(vm);
    case 9:
        ResetScriptCalling();
        return luaSetEffectState(vm);

    default:
        NextScriptCalling();
        return moMoldeoObject::ScriptCalling( vm, iFunctionNumber );
    }
}
Exemple #4
0
int main(int argc, char *argv[]) {
    // Lua test
    sel::State luaState{true};
    luaState["message"] = "Hello world!";
    std::string message = luaState["message"];
    std::cout << "Message: " << message << std::endl;

    // SDL test
    SDL2pp::SDL sdl(SDL_INIT_VIDEO);
    SDL2pp::SDLTTF ttf;
    SDL2pp::SDLImage img;
    SDL2pp::Window win("Hello world", 0, 0, 800, 600, SDL_WINDOWPOS_UNDEFINED);
    for (int i = 0; i < 10; ++i) {
        luaState["number"] = i;
        std::cout << "Number: " << int(luaState["number"]) << std::endl;
        SDL_Delay(1000);
    }

    luaState("print(\"Goodbye from Lua!\")");
}