Commit before the BIG changes...
This commit is contained in:
187
lua.cpp
187
lua.cpp
@@ -23,7 +23,7 @@ extern "C" {
|
||||
}
|
||||
uint8_t c0 = luaL_checkinteger(L, 1);
|
||||
uint8_t c1 = luaL_checkinteger(L, 2);
|
||||
uint8_t p = luaL_optinteger(L, 1, 0);
|
||||
uint8_t p = luaL_optinteger(L, 3, 0);
|
||||
pal(c0, c1, p);
|
||||
return 0;
|
||||
}
|
||||
@@ -41,8 +41,8 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_pset(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
if (lua_gettop(L) > 2) {
|
||||
uint8_t color = luaL_checkinteger(L, 3);
|
||||
pset(x, y, color);
|
||||
@@ -53,17 +53,17 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_pget(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
lua_pushinteger(L, pget(x, y));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_line(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int y1 = luaL_checkinteger(L, 4);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
if (lua_gettop(L) > 4) {
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
line(x0, y0, x1, y1, color);
|
||||
@@ -74,9 +74,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_hline(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
if (lua_gettop(L) > 3) {
|
||||
uint8_t color = luaL_checkinteger(L, 4);
|
||||
hline(x0, y, x1, color);
|
||||
@@ -87,9 +87,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_vline(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int y1 = luaL_checkinteger(L, 3);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int y1 = luaL_checknumber(L, 3);
|
||||
if (lua_gettop(L) > 3) {
|
||||
uint8_t color = luaL_checkinteger(L, 4);
|
||||
vline(x, y0, y1, color);
|
||||
@@ -100,10 +100,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_rect(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int y1 = luaL_checkinteger(L, 4);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
if (lua_gettop(L) > 4) {
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
rect(x0, y0, x1, y1, color);
|
||||
@@ -114,10 +114,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_rectfill(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int y1 = luaL_checkinteger(L, 4);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
if (lua_gettop(L) > 4) {
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
rectfill(x0, y0, x1, y1, color);
|
||||
@@ -136,8 +136,8 @@ extern "C" {
|
||||
|
||||
static int cpp_print(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
int x = luaL_checkinteger(L, 2);
|
||||
int y = luaL_checkinteger(L, 3);
|
||||
int x = luaL_checknumber(L, 2);
|
||||
int y = luaL_checknumber(L, 3);
|
||||
if (lua_gettop(L) > 3) {
|
||||
uint8_t color = luaL_checkinteger(L, 4);
|
||||
print(str, x, y, color);
|
||||
@@ -148,10 +148,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_clip(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int w = luaL_checkinteger(L, 3);
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
clip(x, y, w, h);
|
||||
return 0;
|
||||
}
|
||||
@@ -164,9 +164,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_circ(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int r = luaL_optinteger(L, 3, 4);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int r = luaL_optnumber(L, 3, 4);
|
||||
if (lua_gettop(L) > 3) {
|
||||
uint8_t color = luaL_checkinteger(L, 4);
|
||||
circ(x, y, r, color);
|
||||
@@ -177,9 +177,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_circfill(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int r = luaL_optinteger(L, 3, 4);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int r = luaL_optnumber(L, 3, 4);
|
||||
if (lua_gettop(L) > 3) {
|
||||
uint8_t color = luaL_checkinteger(L, 4);
|
||||
circfill(x, y, r, color);
|
||||
@@ -190,10 +190,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_oval(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int y1 = luaL_checkinteger(L, 4);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
if (lua_gettop(L) > 4) {
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
oval(x0, y0, x1, y1, color);
|
||||
@@ -204,10 +204,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_ovalfill(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int y1 = luaL_checkinteger(L, 4);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
if (lua_gettop(L) > 4) {
|
||||
uint8_t color = luaL_checkinteger(L, 5);
|
||||
ovalfill(x0, y0, x1, y1, color);
|
||||
@@ -218,8 +218,8 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_sset(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
if (lua_gettop(L) > 2) {
|
||||
uint8_t color = luaL_checkinteger(L, 3);
|
||||
sset(x, y, color);
|
||||
@@ -230,16 +230,16 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_sget(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
lua_pushinteger(L, sget(x, y));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_spr(lua_State *L) {
|
||||
uint8_t n = luaL_checkinteger(L, 1);
|
||||
int x = luaL_checkinteger(L, 2);
|
||||
int y = luaL_checkinteger(L, 3);
|
||||
int x = luaL_checknumber(L, 2);
|
||||
int y = luaL_checknumber(L, 3);
|
||||
float w = luaL_optnumber(L, 4, 1.0f);
|
||||
float h = luaL_optnumber(L, 5, 1.0f);
|
||||
bool flip_x = lua_toboolean(L, 6);
|
||||
@@ -249,14 +249,14 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_sspr(lua_State *L) {
|
||||
int sx = luaL_checkinteger(L, 1);
|
||||
int sy = luaL_checkinteger(L, 2);
|
||||
int sw = luaL_checkinteger(L, 3);
|
||||
int sh = luaL_checkinteger(L, 4);
|
||||
int dx = luaL_checkinteger(L, 5);
|
||||
int dy = luaL_checkinteger(L, 6);
|
||||
int dw = luaL_optinteger(L, 7, 0);
|
||||
int dh = luaL_optinteger(L, 8, 0);
|
||||
int sx = luaL_checknumber(L, 1);
|
||||
int sy = luaL_checknumber(L, 2);
|
||||
int sw = luaL_checknumber(L, 3);
|
||||
int sh = luaL_checknumber(L, 4);
|
||||
int dx = luaL_checknumber(L, 5);
|
||||
int dy = luaL_checknumber(L, 6);
|
||||
int dw = luaL_optnumber(L, 7, 0);
|
||||
int dh = luaL_optnumber(L, 8, 0);
|
||||
bool flip_x = lua_toboolean(L, 9);
|
||||
bool flip_y = lua_toboolean(L, 10);
|
||||
sspr(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
|
||||
@@ -264,10 +264,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_tline(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int y1 = luaL_checkinteger(L, 4);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
int y1 = luaL_checknumber(L, 4);
|
||||
float mx = luaL_checknumber(L, 5);
|
||||
float my = luaL_checknumber(L, 6);
|
||||
float mdx = luaL_optnumber(L, 7, 0.125f);
|
||||
@@ -277,9 +277,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_thline(lua_State *L) {
|
||||
int x0 = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int x1 = luaL_checkinteger(L, 3);
|
||||
int x0 = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int x1 = luaL_checknumber(L, 3);
|
||||
float mx = luaL_checknumber(L, 4);
|
||||
float my = luaL_checknumber(L, 5);
|
||||
float mdx = luaL_optnumber(L, 6, 0.125f);
|
||||
@@ -289,9 +289,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_tvline(lua_State *L) {
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y0 = luaL_checkinteger(L, 2);
|
||||
int y1 = luaL_checkinteger(L, 3);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y0 = luaL_checknumber(L, 2);
|
||||
int y1 = luaL_checknumber(L, 3);
|
||||
float mx = luaL_checknumber(L, 4);
|
||||
float my = luaL_checknumber(L, 5);
|
||||
float mdx = luaL_optnumber(L, 6, 0.0f);
|
||||
@@ -301,27 +301,27 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_mset(lua_State *L) {
|
||||
int celx = luaL_checkinteger(L, 1);
|
||||
int cely = luaL_checkinteger(L, 2);
|
||||
int celx = luaL_checknumber(L, 1);
|
||||
int cely = luaL_checknumber(L, 2);
|
||||
uint8_t snum = luaL_checkinteger(L, 3);
|
||||
mset(celx, cely, snum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_mget(lua_State *L) {
|
||||
int celx = luaL_checkinteger(L, 1);
|
||||
int cely = luaL_checkinteger(L, 2);
|
||||
int celx = luaL_checknumber(L, 1);
|
||||
int cely = luaL_checknumber(L, 2);
|
||||
lua_pushinteger(L, mget(celx, cely));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_map(lua_State *L) {
|
||||
uint8_t celx = luaL_checkinteger(L, 1);
|
||||
uint8_t cely = luaL_checkinteger(L, 2);
|
||||
int sx = luaL_checkinteger(L, 3);
|
||||
int sy = luaL_checkinteger(L, 4);
|
||||
uint8_t celw = luaL_checkinteger(L, 5);
|
||||
uint8_t celh = luaL_checkinteger(L, 6);
|
||||
uint8_t celx = luaL_checknumber(L, 1);
|
||||
uint8_t cely = luaL_checknumber(L, 2);
|
||||
int sx = luaL_checknumber(L, 3);
|
||||
int sy = luaL_checknumber(L, 4);
|
||||
uint8_t celw = luaL_checknumber(L, 5);
|
||||
uint8_t celh = luaL_checknumber(L, 6);
|
||||
uint8_t layer = luaL_optinteger(L, 7, 0);
|
||||
map(celx, cely, sx, sy, celw, celh, layer);
|
||||
return 0;
|
||||
@@ -339,6 +339,27 @@ extern "C" {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouseX(lua_State *L) {
|
||||
lua_pushinteger(L, mouseX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouseY(lua_State *L) {
|
||||
lua_pushinteger(L, mouseY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouseWheel(lua_State *L) {
|
||||
lua_pushinteger(L, mouseWheel());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouseButton(lua_State *L) {
|
||||
uint8_t i = luaL_checkinteger(L, 1);
|
||||
lua_pushboolean(L, mouseButton(i));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_time(lua_State *L) {
|
||||
lua_pushnumber(L, time());
|
||||
return 1;
|
||||
@@ -414,7 +435,11 @@ extern "C" {
|
||||
srand(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_tostr(lua_State *L) {
|
||||
int val = luaL_checknumber(L, 1);
|
||||
lua_pushstring(L, tostr(val));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
lua_State *L;
|
||||
@@ -467,6 +492,11 @@ void lua_init() {
|
||||
lua_pushcfunction(L,cpp_map); lua_setglobal(L, "map");
|
||||
lua_pushcfunction(L,cpp_btn); lua_setglobal(L, "btn");
|
||||
lua_pushcfunction(L,cpp_btnp); lua_setglobal(L, "btnp");
|
||||
lua_pushcfunction(L,cpp_mouseX); lua_setglobal(L, "mouseX");
|
||||
lua_pushcfunction(L,cpp_mouseY); lua_setglobal(L, "mouseY");
|
||||
lua_pushcfunction(L,cpp_mouseWheel); lua_setglobal(L, "mouseWheel");
|
||||
lua_pushcfunction(L,cpp_mouseButton); lua_setglobal(L, "mouseButton");
|
||||
|
||||
lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time");
|
||||
lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs");
|
||||
lua_pushcfunction(L,cpp_ceil); lua_setglobal(L, "ceil");
|
||||
@@ -481,6 +511,7 @@ void lua_init() {
|
||||
lua_pushcfunction(L,cpp_min); lua_setglobal(L, "min");
|
||||
lua_pushcfunction(L,cpp_rnd); lua_setglobal(L, "rnd");
|
||||
lua_pushcfunction(L,cpp_srand); lua_setglobal(L, "srand");
|
||||
lua_pushcfunction(L,cpp_tostr); lua_setglobal(L, "tostr");
|
||||
|
||||
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
||||
|
||||
Reference in New Issue
Block a user