Exemple #1
0
static void luaLoad ( lua_State* L, const std::string& path )
{
	std::string fullpath = "Scripts/" + path + ".lua";
#ifdef NDEBUG
	if (ResourceManager::FileExists("Scripts/" + path + ".lo"))
	{
		fullpath = "Scripts/" + path + ".lo";
	}
	else
	{
		CompileScript(path);
	}
#endif
	SDL_RWops* rwops = ResourceManager::OpenFile(fullpath);
    if (rwops)
    {
        int rc = lua_load(L, luaReader, (void*)rwops, path.c_str());
		SDL_RWclose(rwops);
		if (rc != 0)
		{
			luaHandleError(L);
			return;
		}
        rc = lua_pcall(L, 0, 0, 0);
        if (rc != 0)
        {
            luaHandleError(L);
			return;
        }
    }
    else
    {
        LOG("Scripting::Driver", LOG_WARNING, "Unable to load script: %s", path.c_str());
    }
}
Exemple #2
0
int luaExecute(char *f) {

    int ret = luaL_loadfile(state.lua, f);
    
    if (ret == LUA_ERRSYNTAX) {
        luaHandleError();
        return 0;
    } else if (ret == LUA_ERRMEM) {
        conAdd(LERR, "Out of memory loading %s", f);        
        return 0;
    } else if (ret == 0) {
        // Fall through
    } else {
        conAdd(LERR, "Unknown Lua error: %i", ret);
        return 0;
    }
    
    ret = lua_pcall(state.lua, 0, 0, 0);
    if (ret == 0)
        return 1;
    
    if (ret == LUA_ERRRUN) {
        luaHandleError();
        return 0;
    } else if (ret == LUA_ERRMEM) {
        conAdd(LERR, "Out of memory loading %s", f);        
        return 0;
    } 
    
    conAdd(LERR, "Unknown Lua error: %i", ret);
    return 0;

}
Exemple #3
0
void LuaScript::InvokeSubroutine ( const std::string& name )
{
	lua_getglobal(L, name.c_str());
    if (!lua_isnoneornil(L, -1))
    {
        int rc = lua_pcall(L, 0, 0, 0);
        if (rc > 0)
        {
            luaHandleError(L);
        }
    }
    else
    {
        lua_pop(L, 1);
    }
}
Exemple #4
0
void LuaScript::InvokeSubroutine ( const std::string& name, const std::string& p )
{
	lua_getglobal(L, name.c_str());
    if (!lua_isnoneornil(L, -1))
    {
		lua_pushlstring(L, p.data(), p.length());
        int rc = lua_pcall(L, 1, 0, 0);
        if (rc > 0)
        {
            luaHandleError(L);
        }
    }
    else
    {
        lua_pop(L, 1);
    }
}
Exemple #5
0
void LuaScript::InvokeSubroutine ( const std::string& name, float x, float y )
{
	lua_getglobal(L, name.c_str());
    if (!lua_isnoneornil(L, -1))
    {
		lua_pushnumber(L, x);
		lua_pushnumber(L, y);
        int rc = lua_pcall(L, 2, 0, 0);
        if (rc > 0)
        {
            luaHandleError(L);
        }
    }
    else
    {
        lua_pop(L, 1);
    }
}