Require "integer" instead of "number" in more places

E.g. trying to press mouse button 1.5 via root.fake_input() doesn't make sense.
Previously the code silently truncated the number to an integer. Now it
complains about this instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-06 13:59:14 +01:00
parent 051d0de85f
commit d09ece6b5a
4 changed files with 14 additions and 14 deletions

View File

@ -84,7 +84,7 @@ luaA_object_incref(lua_State *L, int tud, int oud)
/* Get the number of references */ /* Get the number of references */
lua_rawget(L, -2); lua_rawget(L, -2);
/* Get the number of references and increment it */ /* Get the number of references and increment it */
int count = lua_tonumber(L, -1) + 1; int count = lua_tointeger(L, -1) + 1;
lua_pop(L, 1); lua_pop(L, 1);
/* Push the pointer (key) */ /* Push the pointer (key) */
lua_pushlightuserdata(L, pointer); lua_pushlightuserdata(L, pointer);
@ -121,8 +121,8 @@ luaA_object_decref(lua_State *L, int tud, const void *pointer)
/* Get the number of references */ /* Get the number of references */
lua_rawget(L, -2); lua_rawget(L, -2);
/* Get the number of references and decrement it */ /* Get the number of references and decrement it */
int count = lua_tonumber(L, -1) - 1; int count = lua_tointeger(L, -1) - 1;
/* Did we find the item in our table? (tonumber(nil)-1) is -1 */ /* Did we find the item in our table? (tointeger(nil)-1) is -1 */
if (count < 0) if (count < 0)
{ {
buffer_t buf; buffer_t buf;

View File

@ -116,7 +116,7 @@ luaA_button_set_modifiers(lua_State *L, button_t *b)
static int static int
luaA_button_set_button(lua_State *L, button_t *b) luaA_button_set_button(lua_State *L, button_t *b)
{ {
b->button = luaL_checknumber(L, -1); b->button = luaL_checkinteger(L, -1);
luaA_object_emit_signal(L, -3, "property::button", 0); luaA_object_emit_signal(L, -3, "property::button", 0);
return 0; return 0;
} }

12
root.c
View File

@ -171,7 +171,7 @@ luaA_root_fake_input(lua_State *L)
if(lua_type(L, 2) == LUA_TSTRING) { if(lua_type(L, 2) == LUA_TSTRING) {
detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */ detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */
} else { } else {
detail = luaL_checknumber(L, 2); /* keycode */ detail = luaL_checkinteger(L, 2); /* keycode */
} }
} }
else if(A_STREQ(stype, "key_release")) else if(A_STREQ(stype, "key_release"))
@ -180,25 +180,25 @@ luaA_root_fake_input(lua_State *L)
if(lua_type(L, 2) == LUA_TSTRING) { if(lua_type(L, 2) == LUA_TSTRING) {
detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */ detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */
} else { } else {
detail = luaL_checknumber(L, 2); /* keycode */ detail = luaL_checkinteger(L, 2); /* keycode */
} }
} }
else if(A_STREQ(stype, "button_press")) else if(A_STREQ(stype, "button_press"))
{ {
type = XCB_BUTTON_PRESS; type = XCB_BUTTON_PRESS;
detail = luaL_checknumber(L, 2); /* button number */ detail = luaL_checkinteger(L, 2); /* button number */
} }
else if(A_STREQ(stype, "button_release")) else if(A_STREQ(stype, "button_release"))
{ {
type = XCB_BUTTON_RELEASE; type = XCB_BUTTON_RELEASE;
detail = luaL_checknumber(L, 2); /* button number */ detail = luaL_checkinteger(L, 2); /* button number */
} }
else if(A_STREQ(stype, "motion_notify")) else if(A_STREQ(stype, "motion_notify"))
{ {
type = XCB_MOTION_NOTIFY; type = XCB_MOTION_NOTIFY;
detail = luaA_checkboolean(L, 2); /* relative to the current position or not */ detail = luaA_checkboolean(L, 2); /* relative to the current position or not */
x = luaL_checknumber(L, 3); x = luaL_checkinteger(L, 3);
y = luaL_checknumber(L, 4); y = luaL_checkinteger(L, 4);
} }
else else
return 0; return 0;

View File

@ -51,10 +51,10 @@ void
luaA_tostrut(lua_State *L, int idx, strut_t *strut) luaA_tostrut(lua_State *L, int idx, strut_t *strut)
{ {
luaA_checktable(L, idx); luaA_checktable(L, idx);
strut->left = luaA_getopt_number(L, idx, "left", strut->left); strut->left = luaA_getopt_integer(L, idx, "left", strut->left);
strut->right = luaA_getopt_number(L, idx, "right", strut->right); strut->right = luaA_getopt_integer(L, idx, "right", strut->right);
strut->top = luaA_getopt_number(L, idx, "top", strut->top); strut->top = luaA_getopt_integer(L, idx, "top", strut->top);
strut->bottom = luaA_getopt_number(L, idx, "bottom", strut->bottom); strut->bottom = luaA_getopt_integer(L, idx, "bottom", strut->bottom);
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80