void Lua_V2::StopChore() {
	lua_Object choreObj = lua_getparam(1);
	lua_Object fadeTimeObj = lua_getparam(2);

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

	int chore = lua_getuserdata(choreObj);
	float fadeTime = 0.0f;

	if (!lua_isnil(fadeTimeObj)) {
		if (lua_isnumber(fadeTimeObj))
			fadeTime = lua_getnumber(fadeTimeObj);
	}

	Chore *c = EMIChore::getPool().getObject(chore);
	if (c) {
		c->stop((int)(fadeTime * 1000));
	}
}
Beispiel #2
0
void Lua_V2::UpdateSoundPosition() {
	lua_Object idObj = lua_getparam(1);
	lua_Object param2 = lua_getparam(2);
	lua_Object param3 = lua_getparam(3);
	lua_Object param4 = lua_getparam(4);

	if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F'))
		return;

	if (!lua_isnumber(param2) || !lua_isnumber(param3) || !lua_isnumber(param4))
		return;
	
	float x = lua_getnumber(param2);
	float y = lua_getnumber(param3);
	float z = lua_getnumber(param4);
	PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj));
	if (!sound)
		return;
	Math::Vector3d pos(x, y, z);
	sound->setPosition(pos);
}
Beispiel #3
0
void Lua_V2::SetSoundVolume() {
	lua_Object idObj = lua_getparam(1);
	lua_Object volumeObj = lua_getparam(2);
	if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F')) {
		error("Lua_V2::SetSoundVolume: no valid sound id");
		return;
	}
	if (!lua_isnumber(volumeObj)) {
		error("Lua_V2::SetSoundVolume - ERROR: Unknown parameters");
		return;
	}

	int volume = (int)lua_getnumber(volumeObj);
	PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj));

	if (sound) {
		sound->setVolume(convertEmiVolumeToMixer(volume));
	} else {
		warning("Lua_V2:SetSoundVolume: can't find sound track");
	}
}
Beispiel #4
0
void Lua_V2::IsSoundPlaying() {
	lua_Object idObj = lua_getparam(1);

	if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F')) {
		// can't use error since it actually may happen during normal operation
		warning("Lua_V2::IsSoundPlaying - ERROR: Unknown parameters");
		pushbool(false);
		return;
	}

	PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj));
	if (sound) {
		if (sound->isPlaying()) {
			pushbool(true);
			return;
		}
	} else {
		warning("Lua_V2::IsSoundPlaying: no sound track associated");
	}
	pushbool(false);
}
Beispiel #5
0
static void io_readfrom() {
	lua_Object f = lua_getparam(FIRSTARG);
	if (f == LUA_NOOBJECT) {
		if (getfile(FOUTPUT) != getfile(1)) {
			closefile(FINPUT);
			setreturn(1, FINPUT);
		}
	} else if (lua_tag(f) == gettag(IOTAG)) {
		int32 id = lua_getuserdata(f);
		LuaFile *current = getfile(id);
		if (!current) {
			pushresult(0);
			return;
		}
		setreturn(id, FINPUT);
	} else {
		const char *s = luaL_check_string(FIRSTARG);
		Common::String fileName = Common::lastPathComponent(s, '\\');
		LuaFile *current = NULL;
		Common::SeekableReadStream *inFile = NULL;
		Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
		inFile = saveFileMan->openForLoading(fileName);
		if (!inFile) {
			inFile = g_resourceloader->openNewStreamFile(s);
		}
		if (inFile) {
			current = new LuaFile();
			current->_in = inFile;
			current->_filename = s;
		} else {
			warning("liolib.cpp, io_readfrom(): Could not open file %s", s);
		}
		if (!current) {
			delete current;
			pushresult(0);
		} else {
			setreturn(addfile(current), FINPUT);
		}
	}
}
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);
	}
}
static py_object *get_py_object(lua_State *L, int n) {
    lua_Object ltable = lua_getparam(L, n);

    if (!lua_istable(L, ltable))
        lua_error(L, "wrap table not found!");

    py_object *po = (py_object *) malloc(sizeof(py_object));

    if (po == NULL)
        return NULL;

    // python object recover
    lua_pushobject(L, ltable);
    lua_pushstring(L, POBJECT);

    po->o = (PyObject *) lua_getuserdata(L, lua_rawgettable(L));

    lua_pushobject(L, ltable);
    lua_pushstring(L, ASINDX);

    po->asindx = (int) lua_getnumber(L, lua_rawgettable(L));

    return po;
}
Beispiel #8
0
Font *getfont(lua_Object obj) {
	return Font::getPool()->getObject(lua_getuserdata(obj));
}
Beispiel #9
0
Actor *getactor(lua_Object obj) {
	return Actor::getPool()->getObject(lua_getuserdata(obj));
}
Beispiel #10
0
TextObject *gettextobject(lua_Object obj) {
	return TextObject::getPool()->getObject(lua_getuserdata(obj));
}
Beispiel #11
0
PrimitiveObject *getprimitive(lua_Object obj) {
	return PrimitiveObject::getPool()->getObject(lua_getuserdata(obj));
}
Beispiel #12
0
ObjectState *getobjectstate(lua_Object obj) {
	return ObjectState::getPool()->getObject(lua_getuserdata(obj));
}
Beispiel #13
0
PrimitiveObject *LuaBase::getprimitive(lua_Object obj) {
	return PrimitiveObject::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #14
0
static void* check_userdata(int numArg)
{
  lua_Object o = lua_getparam(numArg);
  luaL_arg_check(lua_isuserdata(o), numArg, "userdata expected");
  return lua_getuserdata(o);
}
Beispiel #15
0
Font *LuaBase::getfont(lua_Object obj) {
	return Font::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #16
0
Bitmap *LuaBase::getbitmap(lua_Object obj) {
	return Bitmap::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #17
0
PoolColor *getcolor(lua_Object obj) {
	return PoolColor::getPool()->getObject(lua_getuserdata(obj));
}
static int lua_getboolean(lua_State *L, lua_Object obj) {
    return PyObject_IsTrue((PyObject *) lua_getuserdata(L, obj));
}
static int lua_isboolean(lua_State *L, lua_Object obj) {
    return lua_isuserdata(L, obj) && PyBool_Check((PyObject *) lua_getuserdata(L, obj));
}
Beispiel #20
0
Actor *LuaBase::getactor(lua_Object obj) {
	return Actor::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #21
0
PoolColor *LuaBase::getcolor(lua_Object obj) {
	return PoolColor::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #22
0
TextObject *LuaBase::gettextobject(lua_Object obj) {
	return TextObject::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #23
0
static LuaFile *getfile(const char *name) {
	lua_Object f = lua_getglobal(name);
	if (!ishandler(f))
		luaL_verror("global variable `%.50s' is not a file handle", name);
	return getfile(lua_getuserdata(f));
}
Beispiel #24
0
Color LuaBase::getcolor(lua_Object obj) {
	return Color(lua_getuserdata(obj));
}
Beispiel #25
0
Ihandle* iuplua_checkihandle(int numArg)
{
  lua_Object o = lua_getparam(numArg);
  luaL_arg_check(lua_tag(o)==iuplua_tag, numArg, "handle expected");
  return (Ihandle*)lua_getuserdata(o);
}
Beispiel #26
0
ObjectState *LuaBase::getobjectstate(lua_Object obj) {
	return ObjectState::getPool().getObject(lua_getuserdata(obj));
}
Beispiel #27
0
/***************************************************************************\
* CD_IMAGERGB.                                                              *
\***************************************************************************/
static void *cdimagergb_checkdata(int param)
{
    lua_Object imagergb;
    static char data_s[50];

    imagergb = lua_getparam(param);
    if (lua_isnil(imagergb))
        lua_error("cdCreateCanvas CD_IMAGERGB: data is a NIL imagergb!");

    if (lua_isstring(imagergb))
    {
        char* str = lua_getstring(imagergb);
        strcpy(data_s, str);
    }
    else
    {
        lua_Object res;
        int bitmap_tag = (int)lua_getnumber(lua_getglobal(BITMAP_TAG));

        if (lua_tag(imagergb) == bitmap_tag)
        {
            bitmap_t *imagergb_p;

            imagergb_p = (bitmap_t *) lua_getuserdata(imagergb);
            if (!imagergb_p->image)
                lua_error("cdCreateCanvas CD_IMAGERGB: data is a killed imagergb!");

            if (imagergb_p->image->type != CD_RGB && imagergb_p->image->type != CD_RGBA)
                lua_error("cdCreateCanvas CD_IMAGERGB: bitmap should be of type rgb or rgba!");

            res = lua_getparam(param+1);
            if (res == LUA_NOOBJECT || lua_isnil(res))
            {
                if (imagergb_p->image->type == CD_RGBA)
                    sprintf(data_s, "%dx%d %p %p %p %p -a", imagergb_p->image->w, imagergb_p->image->h,
                            cdBitmapGetData(imagergb_p->image, CD_IRED),
                            cdBitmapGetData(imagergb_p->image, CD_IGREEN),
                            cdBitmapGetData(imagergb_p->image, CD_IBLUE),
                            cdBitmapGetData(imagergb_p->image, CD_IALPHA));
                else
                    sprintf(data_s, "%dx%d %p %p %p", imagergb_p->image->w, imagergb_p->image->h,
                            cdBitmapGetData(imagergb_p->image, CD_IRED),
                            cdBitmapGetData(imagergb_p->image, CD_IGREEN),
                            cdBitmapGetData(imagergb_p->image, CD_IBLUE));
            }
            else
            {
                double res_f = lua_getnumber(res);
                if (imagergb_p->image->type == CD_RGBA)
                    sprintf(data_s, "%dx%d %p %p %p %p -r%g -a", imagergb_p->image->w, imagergb_p->image->h,
                            cdBitmapGetData(imagergb_p->image, CD_IRED),
                            cdBitmapGetData(imagergb_p->image, CD_IGREEN),
                            cdBitmapGetData(imagergb_p->image, CD_IBLUE),
                            cdBitmapGetData(imagergb_p->image, CD_IALPHA),
                            res_f);
                else
                    sprintf(data_s, "%dx%d %p %p %p -r%g", imagergb_p->image->w, imagergb_p->image->h,
                            cdBitmapGetData(imagergb_p->image, CD_IRED),
                            cdBitmapGetData(imagergb_p->image, CD_IGREEN),
                            cdBitmapGetData(imagergb_p->image, CD_IBLUE),
                            res_f);
            }
        }
        else
        {
            imagergb_t *imagergb_p;
            int imagergb_tag = (int)lua_getnumber(lua_getglobal(IMAGERGB_TAG));

            if (lua_tag(imagergb) != imagergb_tag)
            {
                imagergba_t *imagergba_p;
                int imagergba_tag = (int)lua_getnumber(lua_getglobal(IMAGERGBA_TAG));
                if (lua_tag(imagergb) != imagergba_tag)
                    lua_error("cdCreateCanvas CD_IMAGERGB: data should be of type imagergb_tag or imagergba_tag!");

                imagergba_p = (imagergba_t *) lua_getuserdata(imagergb);
                if (!(imagergba_p->red && imagergba_p->green && imagergba_p->blue))
                    lua_error("cdCreateCanvas CD_IMAGERGB: data is a killed imagergba!");

                res = lua_getparam(param+1);
                if (res == LUA_NOOBJECT || lua_isnil(res))
                {
                    sprintf(data_s, "%dx%d %p %p %p", imagergba_p->width, imagergba_p->height,
                            imagergba_p->red, imagergba_p->green, imagergba_p->blue);
                }
                else
                {
                    double res_f = lua_getnumber(res);
                    sprintf(data_s, "%dx%d %p %p %p -r%g", imagergba_p->width, imagergba_p->height,
                            imagergba_p->red, imagergba_p->green, imagergba_p->blue, res_f);
                }

                return data_s;
            }

            imagergb_p = (imagergb_t *) lua_getuserdata(imagergb);
            if (!(imagergb_p->red && imagergb_p->green && imagergb_p->blue))
                lua_error("cdCreateCanvas CD_IMAGERGB: data is a killed imagergb!");

            res = lua_getparam(param+1);
            if (res == LUA_NOOBJECT || lua_isnil(res))
            {
                sprintf(data_s, "%dx%d %p %p %p", imagergb_p->width, imagergb_p->height,
                        imagergb_p->red, imagergb_p->green, imagergb_p->blue);
            }
            else
            {
                double res_f = lua_getnumber(res);
                sprintf(data_s, "%dx%d %p %p %p -r%g", imagergb_p->width, imagergb_p->height,
                        imagergb_p->red, imagergb_p->green, imagergb_p->blue, res_f);
            }
        }
    }

    return data_s;
}