Created
February 27, 2016 16:09
-
-
Save renb0/57bcd4769de0d2524bf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int graphicsLine(lua_State *L) { // love.graphics.line() -- Semi-Broken | |
if (sf2d_get_current_screen() == currentScreen) { | |
int argc = lua_gettop(L); | |
//Table version | |
if( argc == 1 ) { | |
int tableLen = lua_objlen(L, 1); | |
lua_settop(L, 1); //Remove redundant args | |
luaL_checktype(L, 1, LUA_TTABLE); | |
if( tableLen >= 4 ) { | |
if( tableLen % 2 == 0 ) { | |
lua_pushnil(L); | |
int x, y, px, py = 0; | |
for(int i = 0; i < tableLen; i+=2 ) | |
{ | |
px = x; | |
py = y; | |
//luaL_error(L, tableLen-i); | |
x = luaL_checknumber(L, tableLen-i); | |
y = luaL_checknumber(L, tableLen-(i+1) ); | |
if( i >= 4 ) { | |
sf2d_draw_line(x, y, px, py, getCurrentColor()); | |
} | |
} | |
} | |
else { | |
luaL_error(L, "Number of vertex components must be a multiple of two"); | |
} | |
} else { | |
luaL_error(L, "Need at least two vertices to draw a line"); | |
} | |
} | |
//Non-table line | |
if( argc == 4 ) { | |
int x1 = luaL_checknumber(L, 1); | |
int y1 = luaL_checknumber(L, 2); | |
int x2 = luaL_checknumber(L, 3); | |
int y2 = luaL_checknumber(L, 4); | |
sf2d_draw_line(x1, y1, x2, y2, getCurrentColor()); | |
return 0; | |
} | |
//Polyline version | |
return 0; | |
if ((argc/2)*2 == argc) { | |
for(int i; i < argc / 2; i++) { | |
int t = i * 4; | |
int x1 = luaL_checkinteger(L, t + 1); | |
int y1 = luaL_checkinteger(L, t + 2); | |
int x2 = luaL_checkinteger(L, t + 3); | |
int y2 = luaL_checkinteger(L, t + 4); | |
translateCoords(&x1, &y1); | |
translateCoords(&x2, &y2); | |
sf2d_draw_line(x1, y1, x2, y2, getCurrentColor()); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment