lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


lua_isinteger is not available in lua 5.1 and 5.2.
Avoid it to provide compatibility.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 structs.c | 97 +++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 51 insertions(+), 46 deletions(-)

diff --git a/structs.c b/structs.c
index ff27642..0e1224f 100644
--- a/structs.c
+++ b/structs.c
@@ -5,6 +5,11 @@
 #include <string.h>
 #include "compat.h"
 
+static int isinteger (lua_State *L, int idx)
+{
+	return lua_tointeger(L, idx) == lua_tonumber(L, idx);
+}
+
 static int luausb_generic_index(lua_State* L)
 {
 	lua_getmetatable(L, 1);
@@ -134,7 +139,7 @@ static int luausb_set_device_descriptor_bLength(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bLength (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -160,7 +165,7 @@ static int luausb_set_device_descriptor_bDescriptorType(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDescriptorType (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -186,7 +191,7 @@ static int luausb_set_device_descriptor_bcdUSB(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bcdUSB (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -212,7 +217,7 @@ static int luausb_set_device_descriptor_bDeviceClass(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDeviceClass (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -238,7 +243,7 @@ static int luausb_set_device_descriptor_bDeviceSubClass(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDeviceSubClass (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -264,7 +269,7 @@ static int luausb_set_device_descriptor_bDeviceProtocol(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDeviceProtocol (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -290,7 +295,7 @@ static int luausb_set_device_descriptor_bMaxPacketSize0(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bMaxPacketSize0 (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -316,7 +321,7 @@ static int luausb_set_device_descriptor_idVendor(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field idVendor (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -342,7 +347,7 @@ static int luausb_set_device_descriptor_idProduct(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field idProduct (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -368,7 +373,7 @@ static int luausb_set_device_descriptor_bcdDevice(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bcdDevice (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -394,7 +399,7 @@ static int luausb_set_device_descriptor_iManufacturer(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field iManufacturer (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -420,7 +425,7 @@ static int luausb_set_device_descriptor_iProduct(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field iProduct (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -446,7 +451,7 @@ static int luausb_set_device_descriptor_iSerialNumber(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field iSerialNumber (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -472,7 +477,7 @@ static int luausb_set_device_descriptor_bNumConfigurations(lua_State* L)
 {
 	struct libusb_device_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bNumConfigurations (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -606,7 +611,7 @@ static int luausb_set_endpoint_descriptor_bLength(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bLength (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -632,7 +637,7 @@ static int luausb_set_endpoint_descriptor_bDescriptorType(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDescriptorType (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -658,7 +663,7 @@ static int luausb_set_endpoint_descriptor_bEndpointAddress(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bEndpointAddress (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -684,7 +689,7 @@ static int luausb_set_endpoint_descriptor_bmAttributes(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bmAttributes (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -710,7 +715,7 @@ static int luausb_set_endpoint_descriptor_wMaxPacketSize(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field wMaxPacketSize (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -736,7 +741,7 @@ static int luausb_set_endpoint_descriptor_bInterval(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bInterval (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -762,7 +767,7 @@ static int luausb_set_endpoint_descriptor_bRefresh(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bRefresh (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -788,7 +793,7 @@ static int luausb_set_endpoint_descriptor_bSynchAddress(lua_State* L)
 {
 	struct libusb_endpoint_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bSynchAddress (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -949,7 +954,7 @@ static int luausb_set_interface_descriptor_bLength(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bLength (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -975,7 +980,7 @@ static int luausb_set_interface_descriptor_bDescriptorType(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDescriptorType (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1001,7 +1006,7 @@ static int luausb_set_interface_descriptor_bInterfaceNumber(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bInterfaceNumber (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1027,7 +1032,7 @@ static int luausb_set_interface_descriptor_bAlternateSetting(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bAlternateSetting (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1053,7 +1058,7 @@ static int luausb_set_interface_descriptor_bNumEndpoints(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bNumEndpoints (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1079,7 +1084,7 @@ static int luausb_set_interface_descriptor_bInterfaceClass(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bInterfaceClass (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1105,7 +1110,7 @@ static int luausb_set_interface_descriptor_bInterfaceSubClass(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bInterfaceSubClass (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1131,7 +1136,7 @@ static int luausb_set_interface_descriptor_bInterfaceProtocol(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bInterfaceProtocol (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1157,7 +1162,7 @@ static int luausb_set_interface_descriptor_iInterface(lua_State* L)
 {
 	struct libusb_interface_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field iInterface (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1325,7 +1330,7 @@ static int luausb_set_interface_num_altsetting(lua_State* L)
 {
 	struct libusb_interface* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field num_altsetting (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1434,7 +1439,7 @@ static int luausb_set_config_descriptor_bLength(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bLength (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1460,7 +1465,7 @@ static int luausb_set_config_descriptor_bDescriptorType(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bDescriptorType (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1486,7 +1491,7 @@ static int luausb_set_config_descriptor_wTotalLength(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field wTotalLength (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1512,7 +1517,7 @@ static int luausb_set_config_descriptor_bNumInterfaces(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bNumInterfaces (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1538,7 +1543,7 @@ static int luausb_set_config_descriptor_bConfigurationValue(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bConfigurationValue (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1564,7 +1569,7 @@ static int luausb_set_config_descriptor_iConfiguration(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field iConfiguration (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1590,7 +1595,7 @@ static int luausb_set_config_descriptor_bmAttributes(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field bmAttributes (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1616,7 +1621,7 @@ static int luausb_set_config_descriptor_MaxPower(lua_State* L)
 {
 	struct libusb_config_descriptor* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field MaxPower (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1949,7 +1954,7 @@ static int luausb_set_transfer_flags(lua_State* L)
 {
 	struct libusb_transfer* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field flags (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -1975,7 +1980,7 @@ static int luausb_set_transfer_endpoint(lua_State* L)
 {
 	struct libusb_transfer* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field endpoint (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -2001,7 +2006,7 @@ static int luausb_set_transfer_type(lua_State* L)
 {
 	struct libusb_transfer* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field type (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -2027,7 +2032,7 @@ static int luausb_set_transfer_timeout(lua_State* L)
 {
 	struct libusb_transfer* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field timeout (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -2053,7 +2058,7 @@ static int luausb_set_transfer_status(lua_State* L)
 {
 	struct libusb_transfer* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field status (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
@@ -2079,7 +2084,7 @@ static int luausb_set_transfer_actual_length(lua_State* L)
 {
 	struct libusb_transfer* udata;
 	lua_Number value;
-	if (!lua_isinteger(L, 2))
+	if (!isinteger(L, 2))
 	{
 		lua_pushliteral(L, "invalid value for field actual_length (integer expected, got ");
 		lua_pushstring(L, luaL_typename(L, 2));
-- 
2.1.4