bool CLuaRules::DrawShield(int unitID, int weaponID)
{
	if (!haveDrawShield)
		return false;

	LUA_CALL_IN_CHECK(L);
	lua_checkstack(L, 5);

	static const LuaHashString cmdStr("DrawShield");

	if (!cmdStr.GetRegistryFunc(L))
		return false;

	const bool oldDrawState = LuaOpenGL::IsDrawingEnabled();
	LuaOpenGL::SetDrawingEnabled(true);

	lua_pushnumber(L, unitID);
	lua_pushnumber(L, weaponID);
	lua_pushnumber(L, game->GetDrawMode());

	const bool success = RunCallIn(cmdStr, 3, 1);
	LuaOpenGL::SetDrawingEnabled(oldDrawState);

	if (!success)
		return false;
	if (!lua_isboolean(L, -1)) {
		LOG_L(L_WARNING, "%s() bad return-type (bool expected, got %s)", (cmdStr.GetString()).c_str(), lua_typename(L, lua_type(L, -1)));
		lua_pop(L, 1);
		return false;
	}

	const bool retval = !!lua_toboolean(L, -1);
	lua_pop(L, 1);
	return retval;
}
Exemplo n.º 2
0
void CLuaHandleSynced::RecvFromSynced(lua_State *srcState, int args)
{
	SELECT_UNSYNCED_LUA_STATE();

#if ((LUA_MT_OPT & LUA_STATE) && (LUA_MT_OPT & LUA_MUTEX))
	if (!SingleState() && srcState != L) { // Sim thread sends to unsynced --> delay it
		DelayRecvFromSynced(srcState, args);
		return;
	}
	// Draw thread, delayed already, execute it
#endif

	static const LuaHashString cmdStr("RecvFromSynced");
	//LUA_CALL_IN_CHECK(L); -- not valid here

	if (!cmdStr.GetRegistryFunc(L))
		return; // the call is not defined
	lua_insert(L, 1); // place the function

	// call the routine
	SetAllowChanges(false);
	SetHandleSynced(L, false);

	lua_State* L_Prev = ForceUnsyncedState();
	RunCallIn(cmdStr, args, 0);
	RestoreState(L_Prev);

	SetHandleSynced(L, true);
	SetAllowChanges(true);
}
Exemplo n.º 3
0
inline bool CLuaHandle::PushUnsyncedCallIn(const LuaHashString& hs)
{
	// LuaUI keeps these call-ins in the Global table,
	// the synced handles keep them in the Registry table
	if (userMode) {
		return hs.GetGlobalFunc(L);
	} else {
		return hs.GetRegistryFunc(L);
	}
}
Exemplo n.º 4
0
void CLuaHandleSynced::RecvFromSynced(int args)
{
	//LUA_CALL_IN_CHECK(L); -- not valid here
	static const LuaHashString cmdStr("RecvFromSynced");
	if (!cmdStr.GetRegistryFunc(L)) {
		return; // the call is not defined
	}
	lua_insert(L, 1); // place the function

	// call the routine
	allowChanges = false;
	synced = false;

	RunCallIn(cmdStr, args, 0);

	synced = true;
	allowChanges = true;

	return;
}
Exemplo n.º 5
0
const char* CLuaRules::AICallIn(const char* data, int inSize, int* outSize)
{
	if (!haveAICallIn) {
		return NULL;
	}

	LUA_CALL_IN_CHECK(L);
	lua_checkstack(L, 3);
	static const LuaHashString cmdStr("AICallIn");
	if (!cmdStr.GetRegistryFunc(L)) {
		return NULL;
	}

	int argCount = 0;
	if (data != NULL) {
		if (inSize < 0) {
			inSize = strlen(data);
		}
		lua_pushlstring(L, data, inSize);
		argCount = 1;
	}

	if (!RunCallIn(cmdStr, argCount, 1)) {
		return NULL;
	}

	if (!lua_isstring(L, -1)) {
		lua_pop(L, 1);
		return NULL;
	}

	size_t len;
	const char* outData = lua_tolstring(L, -1, &len);
	if (outSize != NULL) {
		*outSize = len;
	}

	lua_pop(L, 1);

	return outData;
}
Exemplo n.º 6
0
bool CLuaRules::DrawUnit(int unitID)
{
	if (!haveDrawUnit) {
		return false;
	}

	LUA_CALL_IN_CHECK(L);
	lua_checkstack(L, 4);
	static const LuaHashString cmdStr("DrawUnit");
	if (!cmdStr.GetRegistryFunc(L)) {
		return false;
	}

	const bool oldGLState = LuaOpenGL::IsDrawingEnabled();
	LuaOpenGL::SetDrawingEnabled(true);

	lua_pushnumber(L, unitID);
	lua_pushnumber(L, game->GetDrawMode());

	const bool success = RunCallIn(cmdStr, 2, 1);

	LuaOpenGL::SetDrawingEnabled(oldGLState);

	if (!success) {
		return false;
	}

	if (!lua_isboolean(L, -1)) {
		logOutput.Print("%s() bad return value\n", cmdStr.GetString().c_str());
		lua_pop(L, 1);
		return false;
	}

	const bool retval = !!lua_toboolean(L, -1);
	lua_pop(L, 1);
	return retval;
}