示例#1
0
void Lua_V2::MakeScreenTextures() {
	lua_Object indexObj = lua_getparam(1);

	if (!lua_isnil(indexObj) && lua_isnumber(indexObj)) {
		/*int index = (int)lua_getnumber(indexObj);*/
		// The index does not seem to matter

		g_driver->makeScreenTextures();
		lua_pushnumber(1.0);
	} else {
		lua_pushnil();
	}
}
示例#2
0
void Lua_V2::LocalizeString() {
	char msgId[50], buf[1000];
	lua_Object strObj = lua_getparam(1);
	msgId[0] = 0;

	if (lua_isstring(strObj)) {
		const char *str = lua_getstring(strObj);
		Common::String msg = parseMsgText(str, msgId);
		sprintf(buf, "/%s/%s", msgId, msg.c_str());

		lua_pushstring(buf);
	}
}
示例#3
0
void Lua_V1::LockFont() {
	lua_Object param1 = lua_getparam(1);
	if (lua_isstring(param1)) {
		const char *fontName = lua_getstring(param1);
		Font *result = g_resourceloader->loadFont(fontName);
		if (result) {
			lua_pushusertag(result->getId(), MKTAG('F','O','N','T'));
			return;
		}
	}

	lua_pushnil();
}
示例#4
0
void Lua_V1::DisableControl() {
	lua_Object numObj = lua_getparam(1);

	if (!lua_isnumber(numObj)) {
		lua_pushnil();
		return;
	}
	int num = (int)lua_getnumber(numObj);
	if (num < 0 || num >= KEYCODE_EXTRA_LAST)
		error("control identifier out of range");

	g_grim->disableControl(num);
}
示例#5
0
/* allows the setting error control string in unicode string conversion */
static void _set_unicode_encoding_errorhandler(lua_State *L, int stackpos) {
    lua_Object lobj = lua_getparam(L, stackpos);
    if (lua_isstring(L, lobj)) {
        char *handler = lua_getstring(L, lobj);
        lobj = lua_getparam(L, stackpos + 1);
        if (lobj == LUA_NOOBJECT ? 1 : (int) lua_getnumber(L, lobj)) { // default true
            char *handlers[] = {"strict", "replace", "ignore"};
            bool found = false;
            for (int index = 0; index < 3; index++) {
                if (strcmp(handlers[index], handler) == 0) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                lua_new_error(L, "error handler to unicode string invalid. " \
                             "choices are: \"strict\", \"replace\", \"ignore\"");
            }
        }
        python_setstring(L, PY_UNICODE_ENCODING_ERRORHANDLER, handler);
    }
}
示例#6
0
static int write_int (int just, int m, int n)
{
  char buffer[100];
  lua_Object p = lua_getparam(1);
  int number;
  if (!lua_isnumber(p)) return 0;
  number = (int)lua_getnumber(p);
  if (n >= 0)
    sprintf(buffer, "%.*d", n, number);
  else
    sprintf(buffer, "%d", number);
  return write_string(buffer, just, m);
}
示例#7
0
static void io_write (void)
{
  int status = 0;
  if (lua_getparam (2) == LUA_NOOBJECT)   /* free format */
  {
    lua_Object o1 = lua_getparam(1);
    if (lua_isnumber(o1))
      status = fprintf (out, "%g", lua_getnumber(o1)) >= 0;
    else if (lua_isstring(o1))
      status = fprintf (out, "%s", lua_getstring(o1)) >= 0;
  }
  else					/* formated */
  {
    int just, m, n;
    switch (getformat (lua_check_string(2, "write"), &just, &m, &n))
    {
      case 's':
      {
        lua_Object p = lua_getparam(1);
        if (lua_isstring(p))
          status = write_string(lua_getstring(p), just, m);
        else
          status = 0;
        break;
      }
      case 'f':
        status = write_float(just, m, n);
        break;
      case 'i':
        status = write_int(just, m, n);
        break;
    }
  }
  if (status)
    lua_pushnumber(status);
  else
    lua_pushnil();
}
示例#8
0
void Lua_V1::DrawLine() {
	Common::Point p1, p2;
	PoolColor *color = NULL;;
	lua_Object x1Obj = lua_getparam(1);
	lua_Object y1Obj = lua_getparam(2);
	lua_Object x2Obj = lua_getparam(3);
	lua_Object y2Obj = lua_getparam(4);
	lua_Object tableObj = lua_getparam(5);

	if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
		lua_pushnil();
		return;
	}

	p1.x = (int)lua_getnumber(x1Obj);
	p1.y = (int)lua_getnumber(y1Obj);
	p2.x = (int)lua_getnumber(x2Obj);
	p2.y = (int)lua_getnumber(y2Obj);

	int layer = 2;
	if (lua_istable(tableObj)) {
		lua_pushobject(tableObj);
		lua_pushstring("color");
		lua_Object colorObj = lua_gettable();
		if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
			color = getcolor(colorObj);
		}
		lua_pushobject(tableObj);
		lua_pushstring("layer");
		lua_Object layerObj = lua_gettable();
		if (lua_isnumber(layerObj))
			layer = (int)lua_getnumber(layerObj);
	}

	PrimitiveObject *p = new PrimitiveObject();
	p->createLine(p1, p2, color); // TODO Add layer support
	lua_pushusertag(p->getId(), MKTAG('P','R','I','M'));
}
示例#9
0
void Lua_V1::DrawRectangle() {
	Common::Point p1, p2;
	PoolColor *color = NULL;
	lua_Object objX1 = lua_getparam(1);
	lua_Object objY1 = lua_getparam(2);
	lua_Object objX2 = lua_getparam(3);
	lua_Object objY2 = lua_getparam(4);
	lua_Object tableObj = lua_getparam(5);

	if (!lua_isnumber(objX1) || !lua_isnumber(objY1) || !lua_isnumber(objX2) || !lua_isnumber(objY2)) {
		lua_pushnil();
		return;
	}
	p1.x = (int)lua_getnumber(objX1);
	p1.y = (int)lua_getnumber(objY1);
	p2.x = (int)lua_getnumber(objX2);
	p2.y = (int)lua_getnumber(objY2);
	bool filled = false;

	if (lua_istable(tableObj)){
		lua_pushobject(tableObj);
		lua_pushstring("color");
		lua_Object colorObj = lua_gettable();
		if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
			color = getcolor(colorObj);
		}

		lua_pushobject(tableObj);
		lua_pushstring("filled");
		lua_Object objFilled = lua_gettable();
		if (!lua_isnil(objFilled))
			filled = true;
	}

	PrimitiveObject *p = new PrimitiveObject();
	p->createRectangle(p1, p2, color, filled);
	lua_pushusertag(p->getId(), MKTAG('P','R','I','M')); // FIXME: we use PRIM usetag here
}
示例#10
0
void Lua_V2::PlaySound() {
	lua_Object strObj = lua_getparam(1);
	lua_Object volumeObj = lua_getparam(2);

	if (!lua_isstring(strObj)) {
		error("Lua_V2::PlaySound - ERROR: Unknown parameters");
		return;
	}
	const char *str = lua_getstring(strObj);

	int volume = MAX_EMI_VOLUME;
	if (!lua_isnumber(volumeObj)) {
		warning("Lua_V2::PlaySound - Unexpected parameter(s) found, using default volume for %s", str);
	} else {
		volume = (int)lua_getnumber(volumeObj);
	}

	Common::String filename = addSoundSuffix(str);

	if (!g_emiSound->startSfx(filename, convertEmiVolumeToMixer(volume))) {
		Debug::debug(Debug::Sound | Debug::Scripts, "Lua_V2::PlaySound: Could not open sound '%s'", filename.c_str());
	}
}
示例#11
0
void Lua_V2::DetachActor() {
	// Missing lua parts
	lua_Object attachedObj = lua_getparam(1);

	if (!lua_isuserdata(attachedObj) || lua_tag(attachedObj) != MKTAG('A','C','T','R'))
		return;

	Actor *attached = getactor(attachedObj);
	if (!attached)
		return;

	warning("Lua_V2::DetachActor: detaching %s from parent actor", attached->getName().c_str());
	attached->detach();
}
示例#12
0
void Lua_V2::UnloadActor() {
	lua_Object actorObj = lua_getparam(1);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);
	if (!actor)
		return;

	// This should be safe.
	delete actor;
	g_grim->invalidateActiveActorsList();
}
示例#13
0
static void L2_MakeScreenTextures() {
	lua_Object indexObj = lua_getparam(1);

	if (!lua_isnil(indexObj) && lua_isnumber(indexObj)) {
		int index = (int)lua_getnumber(indexObj);
		warning("L2_MakeScreenTextures, index: %d", index);
		// FIXME: implement missing function
//		if (func(index)) {
			lua_pushnumber(1.0);
			return;
//		}
	}
	lua_pushnil();
}
示例#14
0
文件: lua_v2.cpp 项目: Akz-/residual
// ResidualVM-hacks:
void Lua_V2::GetResidualVMPreference() {
	lua_Object keyObj = lua_getparam(1);

	if (lua_isstring(keyObj)) {
		const Common::String key = lua_getstring(keyObj);

		float value;
		if (g_emiregistry->Get(key, value))
			lua_pushnumber(value);
		else
			lua_pushnil();
	} else
		lua_pushnil();
}
示例#15
0
文件: lua_v2.cpp 项目: Akz-/residual
void Lua_V2::UndimRegion() {
	lua_Object regionObj = lua_getparam(1);

	if (lua_isnumber(regionObj)) {
		int region = (int)lua_getnumber(regionObj);
		// FIXME func(region);
		warning("Lua_V2::UndimRegion: region: %d", region);
	} else {
		lua_pushnil();
		// HACK: The demo uses this to undim the intro-screen.
		// thus UndimRegion(nil) might mean UndimScreen.
		g_driver->setDimLevel(0);
	}
}
示例#16
0
void Lua_V2::ActorStopMoving() {
	lua_Object actorObj = lua_getparam(1);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);

	actor->stopWalking();
	// FIXME: Also stop turning?

	warning("Lua_V2::ActorStopMoving, actor: %s", actor->getName().c_str());
	// FIXME: Inspect the rest of the code to see if there's anything else missing
}
示例#17
0
void Lua_V1::MakeTextObject() {
	lua_Object textObj = lua_getparam(1);
	if (!lua_isstring(textObj)) {
		return;
	}

	TextObject *textObject = new TextObject(false);
	const char *line = lua_getstring(textObj);
	Common::String text = line;

	textObject->setDefaults(&g_grim->_blastTextDefaults);
	lua_Object tableObj = lua_getparam(2);
	if (lua_istable(tableObj))
		setTextObjectParams(textObject, tableObj);

	textObject->setText(text.c_str());

	lua_pushusertag(textObject->getId(), MKTAG('T', 'E', 'X', 'T'));
	if (!(g_grim->getGameFlags() & ADGF_DEMO)) {
		lua_pushnumber(textObject->getBitmapWidth());
		lua_pushnumber(textObject->getBitmapHeight());
	}
}
示例#18
0
void find_script() {
	lua_Object paramObj = lua_getparam(1);
	lua_Type type = ttype(Address(paramObj));

	if (paramObj == LUA_NOOBJECT || (type != LUA_T_CPROTO && type != LUA_T_PROTO && type != LUA_T_TASK)) {
		if (g_grim->getGameType() == GType_GRIM) {
			lua_error("Bad argument to find_script");
		} else {
			warning("find_script with no paramiters");
		}
	}

	if (type == LUA_T_TASK) {
		uint32 task = (uint32)nvalue(Address(paramObj));
		LState *state;
		for (state = lua_rootState->next; state != NULL; state = state->next) {
			if (state->id == task) {
				lua_pushobject(paramObj);
				lua_pushnumber(1.0f);
				return;
			}
		}
	} else if (type == LUA_T_PROTO || type == LUA_T_CPROTO) {
		int task = -1, countTasks = 0;
		bool match;
		LState *state;
		for (state = lua_rootState->next; state != NULL; state = state->next) {
			if (type == LUA_T_PROTO) {
				match = (state->taskFunc.ttype == type && tfvalue(&state->taskFunc) == tfvalue(Address(paramObj)));
			} else {
				match = (state->taskFunc.ttype == type && fvalue(&state->taskFunc) == fvalue(Address(paramObj)));
			}
			if (match) {
				task = state->id;
				countTasks++;
			}
		}
		if (countTasks) {
			assert(task != -1);
			ttype(lua_state->stack.top) = LUA_T_TASK;
			nvalue(lua_state->stack.top) = (float)task;
			incr_top;
			lua_pushnumber((float)countTasks);
			return;
		}
	}

	lua_pushnil();
	lua_pushnumber(0.0f);
}
示例#19
0
void Lua_V2::GetSoundVolume() {
	lua_Object idObj = lua_getparam(1);
	if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F')) {
		error("Lua_V2::GetSoundVolume: Unknown Parameters");
		return;
	}
	PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj));
	if (sound) {
		lua_pushnumber(convertMixerVolumeToEmi(sound->getVolume()));
	} else {
		warning("Lua_V2::GetSoundVolume: can't find sound track");
		lua_pushnumber(convertMixerVolumeToEmi(Audio::Mixer::kMaxChannelVolume));
	}
}
示例#20
0
void Lua_V2::GetActorPuckVector() {
	lua_Object actorObj = lua_getparam(1);
	lua_Object addObj = lua_getparam(2);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) {
		lua_pushnil();
		return;
	}

	Actor *actor = getactor(actorObj);
	if (!actor) {
		lua_pushnil();
		return;
	}

	Math::Vector3d result = actor->getPuckVector();
	if (!lua_isnil(addObj))
		result += actor->getPos();

	lua_pushnumber(result.x());
	lua_pushnumber(result.y());
	lua_pushnumber(result.z());
}
示例#21
0
static void _wrap_ElementGetCSSProperty(void) {

    char * _result;
    char * _arg0;

{
  _arg0 = lua_getstring (lua_getparam (1));
}
    _result = (char *)ElementGetCSSProperty(_arg0);
{
  lua_pushstring (_result);
}
    
}
示例#22
0
void Lua_V2::LoadSound() {
    lua_Object strObj = lua_getparam(1);

    if (!lua_isstring(strObj))
        return;

    const char *str = lua_getstring(strObj);

    Common::String filename = str;
    filename += ".aif";

    PoolSound *sound = new PoolSound(filename);
    lua_pushusertag(sound->getId(), MKTAG('A', 'I', 'F', 'F'));
}
示例#23
0
void Lua_V2::StopActorChores() {
	lua_Object actorObj = lua_getparam(1);
	// Guesswork for boolean parameter
	bool ignoreLoopingChores = getbool(2);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);
	if (!actor)
		return;

	actor->stopAllChores(ignoreLoopingChores);
}
示例#24
0
void Lua_V2::AdvanceChore() {
	lua_Object choreObj = lua_getparam(1);
	lua_Object timeObj = lua_getparam(2);

	if (!lua_isuserdata(choreObj) || lua_tag(choreObj) != MKTAG('C','H','O','R') || !lua_isnumber(timeObj))
		return;

	int chore = lua_getuserdata(choreObj);
	float time = lua_getnumber(timeObj);
	Chore *c = EMIChore::getPool().getObject(chore);
	if (c) {
		if (!c->isPlaying()) {
			warning("AdvanceChore() called on stopped chore %s (%s)",
					c->getName(), c->getOwner()->getFilename().c_str());
			if (c->isLooping()) {
				c->getOwner()->playChoreLooping(c->getName());
			} else {
				c->getOwner()->playChore(c->getName());
			}
		}
		c->setTime(time * 1000);
	}
}
示例#25
0
void Lua_V2::UnloadActor() {
	lua_Object actorObj = lua_getparam(1);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);
	if (!actor)
		return;

	g_grim->invalidateActiveActorsList();
	g_grim->immediatelyRemoveActor(actor);
	delete actor;
}
示例#26
0
static void L2_PlayActorChore() {
	lua_Object actorObj = lua_getparam(1);
	lua_Object choreObj = lua_getparam(2);
	lua_Object costumeObj = lua_getparam(3);
	lua_Object modeObj = lua_getparam(4);
	lua_Object paramObj = lua_getparam(5);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);

	if (!lua_isstring(choreObj) || !lua_isstring(costumeObj))
		lua_pushnil();

	bool mode = false;
	float param = 0.0;

	if (!lua_isnil(modeObj)) {
		if (lua_getnumber(modeObj) != 0.0)
			mode = true;
		if (!lua_isnil(paramObj))
			if (lua_isnumber(paramObj))
				param = lua_getnumber(paramObj);
	}

	const char *choreName = lua_getstring(choreObj);
	const char *costumeName = lua_getstring(costumeObj);

	warning("L2_PlayActorChore: implement opcode actor: %s, chore: %s, costume: %s, mode bool: %d, param: %f",
			actor->getName().c_str(), choreName, costumeName, (int)mode, param);
	// FIXME. code below is a hack, need proper implementation
	actor->setCostume(costumeName);
	Costume *costume = actor->getCurrentCostume();
	costume->playChore(choreName);
	pushbool(true);
}
示例#27
0
void Lua_V1::GetSaveGameData() {
	lua_Object param = lua_getparam(1);
	if (!lua_isstring(param))
		return;
	const char *filename = lua_getstring(param);
	SaveGame *savedState = SaveGame::openForLoading(filename);
	lua_Object result = lua_createtable();

	if (!savedState || !savedState->isCompatible()) {
		lua_pushobject(result);
		lua_pushnumber(2);
		lua_pushstring("mo.set"); // Just a placeholder to not make it throw a lua error
		lua_settable();
		lua_pushobject(result);

		if (!savedState) {
			warning("Savegame %s is invalid", filename);
		} else {
			warning("Savegame %s is incompatible with this ResidualVM build. Save version: %d.%d; current version: %d.%d",
					filename, savedState->saveMajorVersion(), savedState->saveMinorVersion(),
					SaveGame::SAVEGAME_MAJOR_VERSION, SaveGame::SAVEGAME_MINOR_VERSION);
		}
		delete savedState;
		return;
	}
	int32 dataSize = savedState->beginSection('SUBS');

	char str[200];
	int32 strSize;
	int count = 0;

	for (;;) {
		if (dataSize <= 0)
			break;
		strSize = savedState->readLESint32();
		savedState->read(str, strSize);
		lua_pushobject(result);
		lua_pushnumber(count);
		lua_pushstring(str);
		lua_settable();
		dataSize -= strSize;
		dataSize -= 4;
		count++;
	}
	lua_pushobject(result);

	savedState->endSection();
	delete savedState;
}
示例#28
0
void L1_ReadRegistryValue() {
	lua_Object keyObj = lua_getparam(1);

	if (!lua_isstring(keyObj)) {
		lua_pushnil();
		return;
	}
	const char *key = lua_getstring(keyObj);
	const char *val = g_registry->get(key, "");
	// this opcode can return lua_pushnumber due binary nature of some registry entries, but not implemented
	if (val[0] == 0)
		lua_pushnil();
	else
		lua_pushstring(const_cast<char *>(val));
}
示例#29
0
void L1_MakeColor() {
	lua_Object rObj = lua_getparam(1);
	lua_Object gObj = lua_getparam(2);
	lua_Object bObj = lua_getparam(3);
	int r, g, b;

	if (!lua_isnumber(rObj))
		r = 0;
	else
		r = clamp_color((int)lua_getnumber(rObj));

	if (!lua_isnumber(gObj))
		g = 0;
	else
		g = clamp_color((int)lua_getnumber(gObj));

	if (!lua_isnumber(bObj))
		b = 0;
	else
		b = clamp_color((int)lua_getnumber(bObj));

	PoolColor *c = new PoolColor (r, g ,b);
	lua_pushusertag(c->getId(), MKTAG('C','O','L','R'));
}
示例#30
0
void start_script() {
	lua_Object paramObj = lua_getparam(1);
	lua_Type type = paramObj == LUA_NOOBJECT ? LUA_T_NIL : ttype(Address(paramObj));

	if (paramObj == LUA_NOOBJECT || (type != LUA_T_CPROTO && type != LUA_T_PROTO)) {
		lua_error("Bad argument to start_script");
		return;
	}

	LState *state = luaM_new(LState);
	lua_stateinit(state);

	state->next = lua_state->next;
	state->prev = lua_state;
	if (state->next)
		state->next->prev = state;
	lua_state->next = state;

	state->taskFunc.ttype = type;
	state->taskFunc.value = Address(paramObj)->value;

	int l = 2;
	for (lua_Object object = lua_getparam(l++); object != LUA_NOOBJECT; object = lua_getparam(l++)) {
		TObject ptr;
		ptr.ttype = Address(object)->ttype;
		ptr.value = Address(object)->value;
		LState *tmpState = lua_state;
		lua_state = state;
		luaA_pushobject(&ptr);
		lua_state = tmpState;
	}

	ttype(lua_state->stack.top) = LUA_T_TASK;
	nvalue(lua_state->stack.top) = (float)state->id;
	incr_top;
}