Use positive indices for argchecks
This commit is contained in:
parent
8d460d4b04
commit
9a86b0579a
1 changed files with 97 additions and 97 deletions
194
main/paper.h
194
main/paper.h
|
|
@ -52,7 +52,7 @@ static int set_rotation (lua_State *L) {
|
||||||
strcmp(rotation, "portrait") == 0 ||
|
strcmp(rotation, "portrait") == 0 ||
|
||||||
strcmp(rotation, "inverted_landscape") == 0 ||
|
strcmp(rotation, "inverted_landscape") == 0 ||
|
||||||
strcmp(rotation, "inverted_portrait") == 0,
|
strcmp(rotation, "inverted_portrait") == 0,
|
||||||
-1,
|
1,
|
||||||
"expected `rotation` to be either 'landscape', 'portrait', 'inverted_landscape' or 'inverted_portrait'"
|
"expected `rotation` to be either 'landscape', 'portrait', 'inverted_landscape' or 'inverted_portrait'"
|
||||||
);
|
);
|
||||||
epd_set_rotation(
|
epd_set_rotation(
|
||||||
|
|
@ -86,12 +86,12 @@ static int draw_pixel (lua_State *L) {
|
||||||
int x, y, color;
|
int x, y, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x = lua_tonumberx(L, -3, &isnum);
|
x = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `x` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x` to be a number");
|
||||||
y = lua_tonumberx(L, -2, &isnum);
|
y = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `y` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 3, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_draw_pixel(x, y, color, fb);
|
epd_draw_pixel(x, y, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -101,16 +101,16 @@ static int draw_line (lua_State *L) {
|
||||||
int x1, y1, x2, y2, color;
|
int x1, y1, x2, y2, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x1 = lua_tonumberx(L, -5, &isnum);
|
x1 = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -5, "expected `x1` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x1` to be a number");
|
||||||
y1 = lua_tonumberx(L, -4, &isnum);
|
y1 = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `y1` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y1` to be a number");
|
||||||
x2 = lua_tonumberx(L, -3, &isnum);
|
x2 = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `x2` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `x2` to be a number");
|
||||||
y2 = lua_tonumberx(L, -2, &isnum);
|
y2 = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `y2` to be a number");
|
luaL_argcheck(L, isnum, 4, "expected `y2` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 5, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 5, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_draw_line(x1, y1, x2, y2, color, fb);
|
epd_draw_line(x1, y1, x2, y2, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -120,14 +120,14 @@ static int draw_hline (lua_State *L) {
|
||||||
int x, y, length, color;
|
int x, y, length, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x = lua_tonumberx(L, -4, &isnum);
|
x = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x` to be a number");
|
||||||
y = lua_tonumberx(L, -3, &isnum);
|
y = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y` to be a number");
|
||||||
length = lua_tonumberx(L, -2, &isnum);
|
length = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `length` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `length` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 4, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_draw_hline(x, y, length, color, fb);
|
epd_draw_hline(x, y, length, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -137,14 +137,14 @@ static int draw_vline (lua_State *L) {
|
||||||
int x, y, length, color;
|
int x, y, length, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x = lua_tonumberx(L, -4, &isnum);
|
x = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x` to be a number");
|
||||||
y = lua_tonumberx(L, -3, &isnum);
|
y = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y` to be a number");
|
||||||
length = lua_tonumberx(L, -2, &isnum);
|
length = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `length` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `length` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 4, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_draw_vline(x, y, length, color, fb);
|
epd_draw_vline(x, y, length, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -154,14 +154,14 @@ static int draw_circle (lua_State *L) {
|
||||||
int x, y, radius, color;
|
int x, y, radius, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x = lua_tonumberx(L, -4, &isnum);
|
x = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x` to be a number");
|
||||||
y = lua_tonumberx(L, -3, &isnum);
|
y = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y` to be a number");
|
||||||
radius = lua_tonumberx(L, -2, &isnum);
|
radius = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `radius` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `radius` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 4, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_draw_circle(x, y, radius, color, fb);
|
epd_draw_circle(x, y, radius, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -171,14 +171,14 @@ static int fill_circle (lua_State *L) {
|
||||||
int x, y, radius, color;
|
int x, y, radius, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x = lua_tonumberx(L, -4, &isnum);
|
x = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x` to be a number");
|
||||||
y = lua_tonumberx(L, -3, &isnum);
|
y = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y` to be a number");
|
||||||
radius = lua_tonumberx(L, -2, &isnum);
|
radius = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `radius` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `radius` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 4, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_fill_circle(x, y, radius, color, fb);
|
epd_fill_circle(x, y, radius, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -188,16 +188,16 @@ static int draw_rect (lua_State *L) {
|
||||||
int x1, y1, x2, y2, color;
|
int x1, y1, x2, y2, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x1 = lua_tonumberx(L, -5, &isnum);
|
x1 = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -5, "expected `x1` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x1` to be a number");
|
||||||
y1 = lua_tonumberx(L, -4, &isnum);
|
y1 = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `y1` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y1` to be a number");
|
||||||
x2 = lua_tonumberx(L, -3, &isnum);
|
x2 = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `x2` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `x2` to be a number");
|
||||||
y2 = lua_tonumberx(L, -2, &isnum);
|
y2 = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `y2` to be a number");
|
luaL_argcheck(L, isnum, 4, "expected `y2` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 5, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 5, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
EpdRect rect = {
|
EpdRect rect = {
|
||||||
.x = x1,
|
.x = x1,
|
||||||
|
|
@ -213,16 +213,16 @@ static int fill_rect (lua_State *L) {
|
||||||
int x1, y1, x2, y2, color;
|
int x1, y1, x2, y2, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x1 = lua_tonumberx(L, -5, &isnum);
|
x1 = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -5, "expected `x1` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x1` to be a number");
|
||||||
y1 = lua_tonumberx(L, -4, &isnum);
|
y1 = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `y1` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y1` to be a number");
|
||||||
x2 = lua_tonumberx(L, -3, &isnum);
|
x2 = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `x2` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `x2` to be a number");
|
||||||
y2 = lua_tonumberx(L, -2, &isnum);
|
y2 = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `y2` to be a number");
|
luaL_argcheck(L, isnum, 4, "expected `y2` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 5, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 5, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
EpdRect rect = {
|
EpdRect rect = {
|
||||||
.x = x1,
|
.x = x1,
|
||||||
|
|
@ -238,20 +238,20 @@ static int draw_triangle (lua_State *L) {
|
||||||
int x1, y1, x2, y2, x3, y3, color;
|
int x1, y1, x2, y2, x3, y3, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x1 = lua_tonumberx(L, -7, &isnum);
|
x1 = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -7, "expected `x1` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x1` to be a number");
|
||||||
y1 = lua_tonumberx(L, -6, &isnum);
|
y1 = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -6, "expected `y1` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y1` to be a number");
|
||||||
x2 = lua_tonumberx(L, -5, &isnum);
|
x2 = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -5, "expected `x2` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `x2` to be a number");
|
||||||
y2 = lua_tonumberx(L, -4, &isnum);
|
y2 = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `y2` to be a number");
|
luaL_argcheck(L, isnum, 4, "expected `y2` to be a number");
|
||||||
x3 = lua_tonumberx(L, -3, &isnum);
|
x3 = lua_tonumberx(L, 5, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `x3` to be a number");
|
luaL_argcheck(L, isnum, 5, "expected `x3` to be a number");
|
||||||
y3 = lua_tonumberx(L, -2, &isnum);
|
y3 = lua_tonumberx(L, 6, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `y3` to be a number");
|
luaL_argcheck(L, isnum, 6, "expected `y3` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 7, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 7, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_draw_triangle(x1, y1, x2, y2, x3, y3, color, fb);
|
epd_draw_triangle(x1, y1, x2, y2, x3, y3, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -261,20 +261,20 @@ static int fill_triangle (lua_State *L) {
|
||||||
int x1, y1, x2, y2, x3, y3, color;
|
int x1, y1, x2, y2, x3, y3, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
||||||
x1 = lua_tonumberx(L, -7, &isnum);
|
x1 = lua_tonumberx(L, 1, &isnum);
|
||||||
luaL_argcheck(L, isnum, -7, "expected `x1` to be a number");
|
luaL_argcheck(L, isnum, 1, "expected `x1` to be a number");
|
||||||
y1 = lua_tonumberx(L, -6, &isnum);
|
y1 = lua_tonumberx(L, 2, &isnum);
|
||||||
luaL_argcheck(L, isnum, -6, "expected `y1` to be a number");
|
luaL_argcheck(L, isnum, 2, "expected `y1` to be a number");
|
||||||
x2 = lua_tonumberx(L, -5, &isnum);
|
x2 = lua_tonumberx(L, 3, &isnum);
|
||||||
luaL_argcheck(L, isnum, -5, "expected `x2` to be a number");
|
luaL_argcheck(L, isnum, 3, "expected `x2` to be a number");
|
||||||
y2 = lua_tonumberx(L, -4, &isnum);
|
y2 = lua_tonumberx(L, 4, &isnum);
|
||||||
luaL_argcheck(L, isnum, -4, "expected `y2` to be a number");
|
luaL_argcheck(L, isnum, 4, "expected `y2` to be a number");
|
||||||
x3 = lua_tonumberx(L, -3, &isnum);
|
x3 = lua_tonumberx(L, 5, &isnum);
|
||||||
luaL_argcheck(L, isnum, -3, "expected `x3` to be a number");
|
luaL_argcheck(L, isnum, 5, "expected `x3` to be a number");
|
||||||
y3 = lua_tonumberx(L, -2, &isnum);
|
y3 = lua_tonumberx(L, 6, &isnum);
|
||||||
luaL_argcheck(L, isnum, -2, "expected `y3` to be a number");
|
luaL_argcheck(L, isnum, 6, "expected `y3` to be a number");
|
||||||
color = lua_tonumberx(L, -1, &isnum);
|
color = lua_tonumberx(L, 7, &isnum);
|
||||||
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, 7, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
epd_fill_triangle(x1, y1, x2, y2, x3, y3, color, fb);
|
epd_fill_triangle(x1, y1, x2, y2, x3, y3, color, fb);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue