示例#1
0
void tolua_pushusertype (lua_State* L, void* value, int tag)
{
 if (value == NULL)
  lua_pushnil(L);
 else
  lua_pushusertag(L,value,tag);
}
示例#2
0
/* Enables list and tuple as arguments */
static void py_asargs(lua_State *L) {
    py_object *pobj = get_py_object(L, lua_getparam(L, 1));
    if (PyObject_IsListInstance(pobj->object)) {
        PyObject *obj = PyList_AsTuple(pobj->object);
        pobj = py_object_container(L, obj, true);
        pobj->isargs = true;
        lua_pushusertag(L, pobj, python_api_tag(L));
    } else if (PyObject_IsTupleInstance(pobj->object)) {
        Py_INCREF(pobj->object);
        pobj = py_object_container(L, pobj->object, true);
        pobj->isargs = true;
        lua_pushusertag(L, pobj, python_api_tag(L));
    } else {
        luaL_argerror(L, 1, "tuple or list expected");
    }
}
示例#3
0
int luaCompat_newTypedObject(lua_State* L, void* object)
{  /* lua4 */
  int newreference = 0;
  int tag = 0;

  LUASTACK_SET(L);

  luaL_checktype(L, -1, LUA_TNUMBER);

  tag = (int) lua_tonumber(L, -1);

  lua_pop(L, 1);

  /* pushes userdata */
  lua_pushusertag(L, object, LUA_ANYTAG);

  if(lua_tag(L, -1) != tag)
  {
    /* this is the first userdata with this value,
       so corrects the tag */
    lua_settag(L, tag);
    newreference = 1;
  }

  LUASTACK_CLEAN(L, 0);

  return newreference;
}
示例#4
0
文件: iuplua.c 项目: Airr/iup_mac
void iuplua_pushihandle_cb(Ihandle *h)
{
  if (h)
    lua_pushusertag((void*)h, iuplua_tag);
  else
    lua_pushnil();
}
示例#5
0
static void CreateCbox(void)
{
  int tag = (int)lua_getnumber(lua_getglobal("iuplua_tag"));
  Ihandle** params = iuplua_checkihandle_array(1);
  lua_pushusertag(IupCboxv(params),tag);
  free(params);
}
示例#6
0
void L1_GetSaveGameImage() {
	int width = 250, height = 188;
	Bitmap *screenshot;
	int dataSize;

	lua_Object param = lua_getparam(1);
	if (!lua_isstring(param)) {
		lua_pushnil();
		return;
	}
	const char *filename = lua_getstring(param);
	SaveGame *savedState = SaveGame::openForLoading(filename);
	if (!savedState || savedState->saveVersion() != SaveGame::SAVEGAME_VERSION) {
		lua_pushnil();
		return;
	}
	dataSize = savedState->beginSection('SIMG');
	uint16 *data = new uint16[dataSize / 2];
	for (int l = 0; l < dataSize / 2; l++) {
		data[l] = savedState->readLEUint16();
	}
	screenshot = new Bitmap((char *)data, width, height, 16, "screenshot");
	if (screenshot) {
		lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
	} else {
		lua_pushnil();
		warning("Could not restore screenshot from file");
		delete savedState;
		return;
	}
	savedState->endSection();
	delete savedState;
}
示例#7
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);
}
示例#8
0
static void CreateImageRGBA(void)
{
  int i, count, width, height;
  unsigned char *pixels;
  lua_Object n, obj = luaL_tablearg(3);
  width = luaL_check_int(1);
  height = luaL_check_int(2);
  count = width * height * 4;
  pixels = (unsigned char *) malloc(count);

  for (i = 0; i < count; i++)
  {
    lua_beginblock();
    lua_pushobject(obj);
    lua_pushnumber(i+1);

    n = lua_gettable();
    if (!lua_isnumber(n)) 
    {
      lua_endblock();
      lua_error("iupCreateImage: incorrect value in argument");
    }
    pixels[i] = (unsigned char)lua_getnumber(n);
    lua_endblock();
  }

  lua_pushusertag(IupImageRGBA(width, height, pixels), iuplua_tag);
  free(pixels);
}
示例#9
0
static int setreturn (lua_State *L, IOCtrl *ctrl, FILE *f, int inout) {
  if (f == NULL)
    return pushresult(L, 0);
  else {
    setfile(L, ctrl, f, inout);
    lua_pushusertag(L, f, ctrl->iotag);
    return 1;
  }
}
示例#10
0
static int closefile (lua_State *L, IOCtrl *ctrl, FILE *f) {
  if (f == stdin || f == stdout || f == stderr)
    return 1;
  else {
    lua_pushusertag(L, f, ctrl->iotag);
    lua_settag(L, ctrl->closedtag);
    return (CLOSEFILE(L, f) == 0);
  }
}
示例#11
0
文件: iuplua.c 项目: Airr/iup_mac
void iuplua_regihandle(Ihandle *h)
{
  if (h)
  {
    lua_pushusertag((void*)h, iuplua_tag);
    lua_pushstring(IupGetClassName(h));
    lua_call("IupRegisterHandle");
  }
}
示例#12
0
void Table::setUserData( int index, void* userData, int tag )
{
    assert( m_ref >= 0 );

    RestoreStack rs( m_lua );
    lua_getref( m_lua, m_ref );
    lua_pushusertag( m_lua, userData, tag );
    lua_rawseti( m_lua, -2, index );
}
示例#13
0
void Table::setUserData( const String& name, void* userData, int tag )
{
    assert( m_ref >= 0 );

    RestoreStack rs( m_lua );
    lua_getref( m_lua, m_ref );
    lua_pushUTF8( m_lua, name );
    lua_pushusertag( m_lua, userData, tag );
    lua_rawset( m_lua, -3 );
}
示例#14
0
/* Enables dictionaries as keyword arguments */
static void py_askwargs(lua_State *L) {
    py_object *pobj = get_py_object(L, lua_getparam(L, 1));
    if (PyObject_IsDictInstance(pobj->object)) {
        pobj = py_object_container(L, pobj->object, true);
        pobj->iskwargs = true;
        lua_pushusertag(L, pobj, python_api_tag(L));
    } else {
        luaL_argerror(L, 1, "dict expected");
    }
}
示例#15
0
static int io_open (lua_State *L) {
  IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  FILE *f;
  lua_pop(L, 1);  /* remove upvalue */
  f = fopen(luaL_check_string(L, 1), luaL_check_string(L, 2));
  if (f) {
    lua_pushusertag(L, f, ctrl->iotag);
    return 1;
  }
  else
    return pushresult(L, 0);
}
示例#16
0
文件: iuplua.c 项目: Airr/iup_mac
void iuplua_pushihandle(Ihandle *h)
{
  if (h)
  {
    lua_pushusertag((void*)h, iuplua_tag);
    lua_pushstring(IupGetClassName(h));
    lua_call("IupRegisterHandle");
    lua_pushobject(lua_getresult(1));
  }
  else
    lua_pushnil();
}
示例#17
0
void L1_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();
}
示例#18
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 = addSoundSuffix(str);

	PoolSound *sound = new PoolSound(filename);
	lua_pushusertag(sound->getId(), MKTAG('A', 'I', 'F', 'F'));
}
示例#19
0
void Lua_V1::NewObjectState() {
	int setupID = (int)lua_getnumber(lua_getparam(1));
	int val = (int)lua_getnumber(lua_getparam(2));
	ObjectState::Position pos = (ObjectState::Position)val;
	const char *bitmap = lua_getstring(lua_getparam(3));
	const char *zbitmap = NULL;
	if (!lua_isnil(lua_getparam(4)))
		zbitmap = lua_getstring(lua_getparam(4));
	bool transparency = getbool(5);

	ObjectState *state = g_grim->getCurrSet()->addObjectState(setupID, pos, bitmap, zbitmap, transparency);
	lua_pushusertag(state->getId(), MKTAG('S','T','A','T'));
}
示例#20
0
void if2_lua_kernel::constructor( lua_State *L )
{
  jdk_settings settings;
  jdk_lua_get( L, settings );
  if2_lua_kernel *o = new if2_lua_kernel(settings);
  lua_newtable(L);
  lua_pushnumber(L,0); // userdata
  lua_pushusertag(L,(void *)o,otag );
  lua_settable(L,-3);
  
  construct_method(verify_url);
  construct_method(verify_post_data);
  construct_method(verify_received_data);
}
示例#21
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);
}
示例#22
0
void Lua_V1::ScreenShot() {
	int width = (int)lua_getnumber(lua_getparam(1));
	int height = (int)lua_getnumber(lua_getparam(2));
	GrimEngine::EngineMode mode = g_grim->getMode();
	g_grim->setMode(GrimEngine::NormalMode);
	g_grim->updateDisplayScene();
	g_driver->storeDisplay();
	Bitmap *screenshot = g_driver->getScreenshot(width, height);
	g_grim->setMode(mode);
	if (screenshot) {
		lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
	} else {
		lua_pushnil();
	}
}
示例#23
0
void Lua_V2::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);
	Costume *costume = actor->findCostume(costumeName);

	if (costume == NULL) {
		actor->pushCostume(costumeName);
		costume = actor->findCostume(costumeName);
	}

	PoolChore *chore = (PoolChore *)costume->getChore(choreName);
	costume->playChore(choreName);
	if (chore) {
		lua_pushusertag(chore->getId(), MKTAG('C','H','O','R'));
	} else {
		lua_pushnil();
	}

}
示例#24
0
文件: lua_v2.cpp 项目: Akz-/residual
void Lua_V2::NewLayer() {
	lua_Object param1 = lua_getparam(1);
	lua_Object param2 = lua_getparam(2);
	lua_Object param3 = lua_getparam(3);

	const char *til = nullptr;
	int sortorder = 0; // zero = 0;
	if (lua_isstring(param1) && lua_isnumber(param2) && lua_isnumber(param3)) {
		til = lua_getstring(param1);
		sortorder = (int)lua_getnumber(param2);

		//This one is always specified, but also always 0...
		//zero = (int)lua_getnumber(param3);

		Layer *layer = new Layer(til, sortorder);

		// Need to return something that can be looked up later
		lua_pushusertag(layer->getId(), MKTAG('L','A','Y','R'));
	}
}
示例#25
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'));
}
示例#26
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
}
示例#27
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());
	}
}
示例#28
0
void Lua_V1::GetSaveGameImage() {
	int width = 250, height = 188;
	Bitmap *screenshot;
	int dataSize;

	lua_Object param = lua_getparam(1);
	if (!lua_isstring(param)) {
		lua_pushnil();
		return;
	}
	const char *filename = lua_getstring(param);
	SaveGame *savedState = SaveGame::openForLoading(filename);
	if (!savedState || !savedState->isCompatible()) {
		delete savedState;
		lua_pushnil();
		return;
	}
	dataSize = savedState->beginSection('SIMG');
	uint16 *data = new uint16[dataSize / 2];
	for (int l = 0; l < dataSize / 2; l++) {
		data[l] = savedState->readLEUint16();
	}
	Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data);
	screenshot = new Bitmap(buf, width, height, "screenshot");
	delete[] data;
	if (screenshot) {
		lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
	} else {
		lua_pushnil();
		warning("Could not restore screenshot from file");
		delete savedState;
		return;
	}
	savedState->endSection();
	delete savedState;
}
示例#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
int if2_lua_scanner::constructor( lua_State *L )
{
  jdk_map< jdk_str<256>, jdk_str<4096> > settings;
  jdk_str<1024> precompiled_setting;
  jdk_str<1024> setting_prefix;
  int num_files;
  
  jdk_lua_get( L, num_files );
  jdk_lua_get( L, setting_prefix );
  jdk_lua_get( L, precompiled_setting );
  jdk_lua_get( L, settings );
  if2_lua_scanner *o = new if2_lua_scanner(settings,precompiled_setting,setting_prefix,num_files);
  lua_newtable(L);
  lua_pushnumber(L,0); // userdata
  lua_pushusertag(L,(void *)o,otag );
  lua_settable(L,-3);
  
  construct_method(find);
  construct_method(extract);
  construct_method(load);
  construct_method(save);	
  construct_method(add);
  return 0;	
}