示例#1
0
bool gkLuaScript::execute(void)
{
	if (!m_compiled)
		compile();

	if (m_isInvalid)
		return false;

	m_lastRetBoolValue = false;
	m_lastRetStrValue = "";

	lua_State* L = gkLuaManager::getSingleton().getLua();;
	//lua_dumpstack(L);
	lua_pushtraceback(L);
	int trace = lua_gettop(L);

	lua_rawgeti(L, LUA_REGISTRYINDEX, m_script);
	if (lua_pcall(L, 0, LUA_MULTRET, trace) != 0)
	{
		gkPrintf("%s\n", lua_tostring(L, -1));
		dsPrintf("%s\n", lua_tostring(L, -1));
		lua_pop(L, 1);
		m_isInvalid = true;
		return false;
	}
	
	m_lastRetBoolValue = lua_toboolean(L, -1) != 0;
	char* str = (char*)lua_tostring(L, -1);
	if (str) m_lastRetStrValue = str;

	lua_gc(L, LUA_GCSTEP, 1);
	lua_popall(L);
	return true;
}
示例#2
0
void gkLuaScript::compile(void)
{
	if (m_isInvalid)
		return;

	lua_State* L = gkLuaManager::getSingleton().getLua();
	//lua_dumpstack(L);
	{
		lua_pushvalue(L, LUA_GLOBALSINDEX);
		if (luaL_loadbuffer(L, m_text.c_str(), m_text.size() - 1, getName().c_str()) != 0)
		{
			gkPrintf("%s\n", lua_tostring(L, -1));
			dsPrintf("%s\n", lua_tostring(L, -1));
			lua_pop(L, 1);
			m_isInvalid = true;
			return;
		}


		// script function is now on the stack
		int fnc = lua_gettop(L);
		if (!lua_isfunction(L, fnc))
		{
			lua_pop(L, 1);
			m_isInvalid = true;
			return;
		}

		lua_pushvalue(L, fnc);
		m_script = luaL_ref(L, LUA_REGISTRYINDEX);
		lua_popall(L);
	}
	m_compiled = true;
}
示例#3
0
文件: main.c 项目: joedrago/lbm
void lbmCanonicalizePath(char ** dspath, const char * curDir)
{
    char * temp = NULL;
    if (!curDir || !strlen(curDir))
    {
        curDir = ".";
    }

    if (isAbsolutePath(*dspath))
    {
        dsCopy(&temp, *dspath);
    }
    else
    {
        dsPrintf(&temp, "%s/%s", curDir, *dspath);
    }

    dsCleanupSlashes(&temp);
    dsSquashDotDirs(&temp);

    dsCopy(dspath, temp);
    dsDestroy(&temp);
}
示例#4
0
void gkPhysicsDebug::reportErrorWarning(const char* warningString)
{
    dsPrintf("Warning: %s", warningString);
}