Ejemplo n.º 1
0
static void GetClassAttributes(void)
{
  int max_n = luaL_check_int(2);
  char **names = (char **) malloc(max_n * sizeof(char *));
  int n = IupGetClassAttributes(luaL_check_string(1), names, max_n);
  lua_Object tb;
  int i;

  if (n == -1)
  {
    lua_pushnil();
    return;
  }

  tb = lua_createtable();
  for (i = 0; i < n; i++) 
  {
    lua_beginblock();
    lua_pushobject(tb);
    lua_pushnumber(i);
    lua_pushstring(names[i]);
    lua_settable();
    lua_endblock();                /* end a section and starts another */
  }

  lua_pushobject(tb);
  lua_pushnumber(n);
  free(names);
}
Ejemplo n.º 2
0
static void iuplua_index(void)
{
  lua_Object t, f, result;
  t = lua_getparam(1);
  f = lua_getparam(2);
  if (!(lua_isstring(f) && iupStrEqual(lua_getstring(f), "parent"))) 
  {
    lua_Object p;
    lua_pushobject(t);
    lua_pushstring("parent");
    p = lua_gettable();
    if (lua_istable(p)) 
    {
      lua_pushobject(p);
      lua_pushobject(f);
      result = lua_gettable();
      if (lua_isnil(result))
        lua_pushnil();
      else
        lua_pushobject(result);
      return;
    }
  }
  lua_pushnil();
}
Ejemplo n.º 3
0
bool LuaBase::callback(const char *name, const LuaObjects &objects) {
	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring(name);
	lua_Object table = lua_gettable();

	if (lua_istable(table)) {
		lua_pushobject(table);
		lua_pushstring(name);
		lua_Object func = lua_gettable();
		if (lua_isfunction(func)) {
			lua_pushobject(table);
			objects.pushObjects();
			lua_callfunction(func);
		} else {
			lua_endblock();
			return false;
		}
	} else if (lua_isfunction(table)) {
		objects.pushObjects();
		lua_callfunction(table);
	} else if (!lua_isnil(table)) {
		lua_endblock();
		return false;
	}

	lua_endblock();
	return true;
}
Ejemplo n.º 4
0
static void luaB_rawsetglobal (void) {
  char *n = luaL_check_string(1);
  lua_Object value = luaL_nonnullarg(2);
  lua_pushobject(value);
  lua_rawsetglobal(n);
  lua_pushobject(value);  /* return given value */
}
Ejemplo n.º 5
0
static void IupSetIdle(void)
{
  lua_Object obj = lua_getparam(1);
  lua_Object old;
  if (idle_ref != 0)
    old = lua_getref(idle_ref);
  else
    old = LUA_NOOBJECT;
  if (lua_isnil(obj)) 
  {
    lua_unref(idle_ref);
    idle_ref = 0;
    IupSetFunction("IDLE_ACTION", (Icallback) NULL);
  } 
  else 
  {
    if (!lua_isfunction(obj) && !lua_iscfunction(obj))
      lua_error("IupSetIdle: parameter must be a function or a cfunction");
    lua_pushobject(obj);
    idle_ref = lua_ref(1);
    IupSetFunction("IDLE_ACTION", (Icallback) default_idle);
  }

  if (old == LUA_NOOBJECT)
    lua_pushnil();
  else
    lua_pushobject(old);
}
Ejemplo n.º 6
0
void GrimEngine::handleUserPaint() {
	lua_Object func;

	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("userPaintHandler");
	lua_Object handler = lua_gettable();
	if (lua_istable(handler)) {
		lua_pushobject(handler);
		lua_pushstring("userPaintHandler");
		func = lua_gettable();
		if (!lua_isfunction(func))
			error("handleUserPaint: handler not a function");
		lua_pushobject(handler);
	} else if (lua_isfunction(handler)) {
		func = handler;
	} else if (!lua_isnil(handler)) {
		error("handleUserPaint: invalid handler");
		return;
	} else {
		lua_endblock();
		return;
	}

	lua_callfunction(func);

	lua_endblock();
}
Ejemplo n.º 7
0
static void settagmethod (void)
{
  lua_Object nf = luaL_nonnullarg(3);
  lua_pushobject(nf);
  lua_pushobject(lua_settagmethod((int32)luaL_check_number(1),
                                  luaL_check_string(2)));
}
Ejemplo n.º 8
0
int main (int argc, char *argv[])
{
  int i;
  int result = 0;
  iolib_open ();
  strlib_open ();
  mathlib_open ();
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <filename> <arguments>\n", argv[0]);
    exit(1);
  } else {
    lua_Object lua_arg;
    lua_arg = lua_createtable();
    for (i=2; i<argc; i++) {
      lua_pushobject(lua_arg);
      lua_pushnumber((double)(i-1));
      lua_pushstring(argv[i]);
      lua_storesubscript();
    }
    lua_pushobject(lua_arg);
    lua_storeglobal("arg");
    result = lua_dofile (argv[1]);
    if (result) {
      if (result == 2) {
        fprintf(stderr, "lua: cannot execute file `%s' - ", argv[i]);
        perror(NULL);
      }
      return 1;
    }
  }
  return result;
}
Ejemplo n.º 9
0
static void settag (void)
{
  lua_Object o = luaL_tablearg(1);
  lua_pushobject(o);
  lua_settag((int32)luaL_check_number(2));
  lua_pushobject(o);  /* returns first argument */
}
Ejemplo n.º 10
0
static void rawsettable (void)
{
  lua_pushobject(luaL_nonnullarg(1));
  lua_pushobject(luaL_nonnullarg(2));
  lua_pushobject(luaL_nonnullarg(3));
  lua_rawsettable();
}
Ejemplo n.º 11
0
static void rawsetglobal() {
	const char *n = luaL_check_string(1);
	lua_Object value = luaL_nonnullarg(2);
	lua_pushobject(value);
	lua_rawsetglobal(n);
	lua_pushobject(value);  // return given value
}
Ejemplo n.º 12
0
static void getlocal (void) {
  lua_Object func = lua_stackedfunction(luaL_check_int(1));
  lua_Object val;
  char *name;
  if (func == LUA_NOOBJECT)  /* level out of range? */
    return;  /* return nil */
  else if (lua_getparam(2) != LUA_NOOBJECT) {  /* 2nd argument? */
    if ((val = lua_getlocal(func, findlocal(func, 2), &name)) != LUA_NOOBJECT) {
      lua_pushobject(val);
      lua_pushstring(name);
    }
    /* else return nil */
  }
  else {  /* collect all locals in a table */
    lua_Object result = lua_createtable();
    int i;
    for (i=1; ;i++) {
      if ((val = lua_getlocal(func, i, &name)) == LUA_NOOBJECT)
        break;
      lua_pushobject(result);
      lua_pushstring(name);
      lua_pushobject(val);
      lua_settable();  /* result[name] = value */
    }
    lua_pushobject(result);
  }
}
Ejemplo n.º 13
0
void Lua_V2::GetActorChores() {
	lua_Object actorObj = lua_getparam(1);
	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;
	Actor *actor = getactor(actorObj);
	Costume *costume = actor->getCurrentCostume();

	lua_Object result = lua_createtable();
	lua_pushobject(result);

	if (!costume) {
		lua_pushstring("count");
		lua_pushnumber(0);
		lua_settable();
		lua_pushobject(result);
		return;
	}

	int num = costume->getNumChores();

	lua_pushstring("count");
	lua_pushnumber(num);
	lua_settable();

	for (int i = 0; i < num; ++i) {
		lua_pushobject(result);
		lua_pushnumber(i);
		lua_pushusertag(((EMIChore *)costume->getChore(i))->getId(), MKTAG('C','H','O','R'));
		lua_settable();
	}

	lua_pushobject(result);
}
Ejemplo n.º 14
0
static void rawgettable() {
	lua_Object t = luaL_nonnullarg(1);
	lua_Object i = luaL_nonnullarg(2);
	lua_pushobject(t);
	lua_pushobject(i);
	lua_pushobject(lua_rawgettable());
}
Ejemplo n.º 15
0
static void luaB_call (void) {
  lua_Object f = luaL_nonnullarg(1);
  Hash *arg = gethash(2);
  char *options = luaL_opt_string(3, "");
  lua_Object err = lua_getparam(4);
  int narg = (int)getnarg(arg);
  int i, status;
  if (err != LUA_NOOBJECT) {  /* set new error method */
    lua_pushobject(err);
    err = lua_seterrormethod();
  }
  /* push arg[1...n] */
  luaD_checkstack(narg);
  for (i=0; i<narg; i++)
    *(L->stack.top++) = *luaH_getint(arg, i+1);
  status = lua_callfunction(f);
  if (err != LUA_NOOBJECT) {  /* restore old error method */
    lua_pushobject(err);
    lua_seterrormethod();
  }
  if (status != 0) {  /* error in call? */
    if (strchr(options, 'x')) {
      lua_pushnil();
      return;  /* return nil to signal the error */
    }
    else
      lua_error(NULL);
  }
  else {  /* no errors */
    if (strchr(options, 'p'))
      luaA_packresults();
    else
      luaA_passresults();
  }
}
Ejemplo n.º 16
0
void L1_typeOverride() {
	lua_Object data = lua_getparam(1);

	if (lua_isuserdata(data)) {
		switch (lua_tag(data)) {
		case MKTAG('A','C','T','R'):
			lua_pushstring("actor");
			lua_pushnumber(lua_tag(data));
			return;
		case MKTAG('C','O','S','T'):
			lua_pushstring("costume");
			lua_pushnumber(lua_tag(data));
			return;
		case MKTAG('S','E','T',' '):
			lua_pushstring("set");
			lua_pushnumber(lua_tag(data));
			return;
		case MKTAG('K','E','Y','F'):
			lua_pushstring("keyframe");
			lua_pushnumber(lua_tag(data));
			return;
		default:
			break;
		}
	}

	lua_pushobject(data);
	lua_callfunction(lua_getref(refTypeOverride));
	lua_Object param1 = lua_getresult(1);
	lua_Object param2 = lua_getresult(2);
	lua_pushobject(param1);
	lua_pushobject(param2);
}
Ejemplo n.º 17
0
void GrimEngine::savegameCallback() {
	lua_Object funcParam1;

	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("saveGameCallback");
	lua_Object funcParam2 = lua_gettable();

	if (lua_istable(funcParam2)) {
		lua_pushobject(funcParam2);
		lua_pushstring("saveGameCallback");
		funcParam1 = lua_gettable();
		if (lua_isfunction(funcParam1)) {
			lua_pushobject(funcParam2);
			lua_callfunction(funcParam1);
		} else {
			error("GrimEngine::savegameCallback: handler is not a function");
		}
	} else if (lua_isfunction(funcParam2)) {
		funcParam1 = funcParam2;
		lua_callfunction(funcParam1);
	} else if (!lua_isnil(funcParam2)) {
		error("GrimEngine::savegameCallback: invalid handler");
	}
	lua_endblock();
}
Ejemplo n.º 18
0
static void iuplua_setnamespace(char* name, char* new_name)
{
  lua_Object obj = lua_getglobal(name);
  lua_pushobject(iuplua_namespace);
  lua_pushstring(new_name);
  lua_pushobject(obj);
  lua_settable();
}
Ejemplo n.º 19
0
int lua_RtAudio(lua_State *L)
{
    if (lua_gettop(L)== 0)
        lua_pushobject(L, DAC)(RtAudio::UNSPECIFIED);
    else
        lua_pushobject(L, DAC)((RtAudio::Api)lua_tointeger(L,1));
    return 1;
}
Ejemplo n.º 20
0
void L1_EnumerateVideoDevices() {
	lua_Object result = lua_createtable();
	lua_pushobject(result);
	lua_pushnumber(0.0); // id of device
	lua_pushstring(g_driver->getVideoDeviceName()); // name of device
	lua_settable();
	lua_pushobject(result);
}
Ejemplo n.º 21
0
static void rawsettable() {
	lua_Object t = luaL_nonnullarg(1);
	lua_Object i = luaL_nonnullarg(2);
	lua_Object v = luaL_nonnullarg(3);
	lua_pushobject(t);
	lua_pushobject(i);
	lua_pushobject(v);
	lua_rawsettable();
}
Ejemplo n.º 22
0
/* RotateVector takes a vector and rotates it around
 * the point (0,0,0) by the requested number of degrees.
 * This function is used to calculate the locations for
 * getting on and off of the Bone Wagon and for going up
 * and down the slide with the chain at the end of the world.
 */
void L1_RotateVector() {
	lua_Object vecObj = lua_getparam(1);
	lua_Object rotObj = lua_getparam(2);
	lua_Object resObj;
	Graphics::Vector3d vec, rot, resVec;
	float x, y, z;

	if (!lua_istable(vecObj) || !lua_istable(rotObj)) {
		lua_pushnil();
		return;
	}

	lua_pushobject(vecObj);
	lua_pushstring("x");
	x = lua_getnumber(lua_gettable());
	lua_pushobject(vecObj);
	lua_pushstring("y");
	y = lua_getnumber(lua_gettable());
	lua_pushobject(vecObj);
	lua_pushstring("z");
	z = lua_getnumber(lua_gettable());
	vec.set(x, y, z);

	lua_pushobject(rotObj);
	lua_pushstring("x");
	x = lua_getnumber(lua_gettable());
	lua_pushobject(rotObj);
	lua_pushstring("y");
	y = lua_getnumber(lua_gettable());
	lua_pushobject(rotObj);
	lua_pushstring("z");
	z = lua_getnumber(lua_gettable());
	rot.set(x, y, z);

	Graphics::Matrix3 mat;
	mat.buildFromPitchYawRoll(x, y, z);
	mat.transform(&vec);

	resObj = lua_createtable();
	lua_pushobject(resObj);
	lua_pushstring("x");
	lua_pushnumber(vec.x());
	lua_settable();
	lua_pushobject(resObj);
	lua_pushstring("y");
	lua_pushnumber(vec.y());
	lua_settable();
	lua_pushobject(resObj);
	lua_pushstring("z");
	lua_pushnumber(vec.z());
	lua_settable();

	lua_pushobject(resObj);
}
Ejemplo n.º 23
0
static void tree_setnumberintable(lua_Object o, int ref)
{
	/* Set in global table in index o, the value of ref. 
	   If ref is 0, then set nil in the table. */
	lua_pushobject(lua_getglobal("IUPTREEREFERENCETABLE"));
	lua_pushobject(o);
	if(ref == 0)
		lua_pushnil();
	else
	  lua_pushnumber(ref);
	lua_rawsettable();
}
Ejemplo n.º 24
0
/* RotateVector takes a vector and rotates it around
 * the point (0,0,0) by the requested number of degrees.
 * This function is used to calculate the locations for
 * getting on and off of the Bone Wagon and for going up
 * and down the slide with the chain at the end of the world.
 */
void Lua_V1::RotateVector() {
	lua_Object vecObj = lua_getparam(1);
	lua_Object rotObj = lua_getparam(2);

	if (!lua_istable(vecObj) || !lua_istable(rotObj)) {
		lua_pushnil();
		return;
	}

	lua_pushobject(vecObj);
	lua_pushstring("x");
	float x = lua_getnumber(lua_gettable());
	lua_pushobject(vecObj);
	lua_pushstring("y");
	float y = lua_getnumber(lua_gettable());
	lua_pushobject(vecObj);
	lua_pushstring("z");
	float z = lua_getnumber(lua_gettable());
	Math::Vector3d vec(x, y, z);

	lua_pushobject(rotObj);
	lua_pushstring("x");
	Math::Angle pitch = lua_getnumber(lua_gettable());
	lua_pushobject(rotObj);
	lua_pushstring("y");
	Math::Angle yaw = lua_getnumber(lua_gettable());
	lua_pushobject(rotObj);
	lua_pushstring("z");
	Math::Angle roll = lua_getnumber(lua_gettable());

	Math::Matrix3 mat;
	mat.buildFromPitchYawRoll(pitch, yaw, roll);
	mat.transformVector(&vec);

	lua_Object resObj = lua_createtable();
	lua_pushobject(resObj);
	lua_pushstring("x");
	lua_pushnumber(vec.x());
	lua_settable();
	lua_pushobject(resObj);
	lua_pushstring("y");
	lua_pushnumber(vec.y());
	lua_settable();
	lua_pushobject(resObj);
	lua_pushstring("z");
	lua_pushnumber(vec.z());
	lua_settable();

	lua_pushobject(resObj);
}
Ejemplo n.º 25
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;
}
Ejemplo n.º 26
0
static void CreateImage(void)
{
  int i, j;
  lua_Object linha;
  int width, height;
  unsigned char *pixels;
  lua_Object obj = luaL_tablearg(3);
  width = luaL_check_int(1);
  height = luaL_check_int(2);
  pixels = (unsigned char *) malloc(width*height);

  for (i = 1; i <= height; i++) 
  {
    lua_beginblock();
    lua_pushobject(obj);
    lua_pushnumber(i);
    linha = lua_gettable();
    if (!lua_istable(linha)) 
    {
      lua_endblock();
      lua_error("iupCreateImage: incorrect value in argument");
    }

    for (j = 1; j <= width; j++) 
    {
      lua_Object n;
      lua_beginblock();
      lua_pushobject(linha);
      lua_pushnumber(j);
      n = lua_gettable();
      if (!lua_isnumber(n)) 
      {
        lua_endblock();
        lua_error("iupCreateImage: incorrect value in argument");
      }
      pixels[(i - 1) * width + (j - 1)] = (unsigned char) lua_getnumber(n);
      lua_endblock();
    }

    lua_pushobject(obj);
    lua_pushnumber(i);
    lua_pushnil();
    lua_settable();
    lua_endblock();
  }

  lua_pushusertag(IupImage(width, height, pixels), iuplua_tag);
  free(pixels);
}
Ejemplo n.º 27
0
static void getstack (void) {
  lua_Object func = lua_stackedfunction(luaL_check_int(1));
  if (func == LUA_NOOBJECT)  /* level out of range? */
    return;
  else {
    lua_Object result = getfuncinfo(func);
    int currline = lua_currentline(func);
    if (currline > 0)
      settabsi(result, "current", currline);
    lua_pushobject(result);
    lua_pushstring("func");
    lua_pushobject(func);
    lua_settable();  /* result.func = func */
    lua_pushobject(result);
  }
}
Ejemplo n.º 28
0
void L1_SubmitSaveGameData() {
	lua_Object table, table2;
	SaveGame *savedState;
	const char *str;
	table = lua_getparam(1);

	savedState = g_grim->savedState();
	if (!savedState)
		error("Cannot obtain saved game");
	savedState->beginSection('SUBS');
	int count = 0;
	for (;;) {
		lua_pushobject(table);
		lua_pushnumber(count);
		count++;
		table2 = lua_gettable();
		if (lua_isnil(table2))
			break;
		str = lua_getstring(table2);
		int32 len = strlen(str) + 1;
		savedState->writeLESint32(len);
		savedState->write(str, len);
	}
	savedState->endSection();
}
Ejemplo n.º 29
0
void L1_Enumerate3DDevices() {
	lua_Object result = lua_createtable();
	lua_Object numObj = lua_getparam(1);
	if (!lua_isnumber(numObj))
		return;
/*	int num = (int)lua_getnumber(numObj);*/
	lua_pushobject(result);
	lua_pushnumber(-1.0);
	if (g_driver->isHardwareAccelerated()) {
		lua_pushstring("OpenGL"); // type of 3d renderer
	} else {
		lua_pushstring("/engn003/Software"); // type of 3d renderer
	}
	lua_settable();
	lua_pushobject(result);
}
Ejemplo n.º 30
0
void lua_pushelement ( lua_State* luaVM, CClientEntity* pElement )
{
    if ( pElement )
    {
        if ( pElement->IsBeingDeleted ( ) )
        {
            lua_pushboolean ( luaVM, false );
            return;
        }

        ElementID ID = pElement->GetID ();
        if ( ID != INVALID_ELEMENT_ID )
        {
            const char* szClass = NULL;
            CLuaMain* pLuaMain = g_pClientGame->GetLuaManager ()->GetVirtualMachine ( luaVM );
            if ( pLuaMain->IsOOPEnabled () )
                szClass = CLuaClassDefs::GetEntityClass ( pElement );

            lua_pushobject ( luaVM, szClass, ( void* ) reinterpret_cast < unsigned int * > ( ID.Value () ) );
            return;
        }
    }

    lua_pushnil ( luaVM );
}