static void mark_function(lua_State *L, lua_State *dL, const void * parent, const char *desc) { int i; const void * t = readobject(L, dL, parent, desc); if (t == NULL) return; mark_function_env(L,dL,t); for (i=1;; i++) { const char *name = lua_getupvalue(L,-1,i); if (name == NULL) break; mark_object(L, dL, t, name[0] ? name : "[upvalue]"); } if (lua_iscfunction(L,-1)) { if (i==1) { // light c function lua_pushnil(dL); lua_rawsetp(dL, FUNCTION, t); } lua_pop(L,1); } else { lua_Debug ar; luaL_Buffer b; char tmp[16]; lua_getinfo(L, ">S", &ar); luaL_buffinit(dL, &b); luaL_addstring(&b, ar.short_src); sprintf(tmp,":%d",ar.linedefined); luaL_addstring(&b, tmp); luaL_pushresult(&b); lua_rawsetp(dL, SOURCE, t); } }
static void mark_thread(lua_State *L, lua_State *dL, const void * parent, const char *desc) { const void * t = readobject(L, dL, parent, desc); if (t == NULL) return; int level = 0; lua_State *cL = lua_tothread(L,-1); if (cL == L) { level = 1; } else { // mark stack int top = lua_gettop(cL); luaL_checkstack(cL, 1, NULL); int i; char tmp[16]; for (i=0;i<top;i++) { lua_pushvalue(cL, i+1); sprintf(tmp, "[%d]", i+1); mark_object(cL, dL, cL, tmp); } } lua_Debug ar; luaL_Buffer b; luaL_buffinit(dL, &b); while (lua_getstack(cL, level, &ar)) { char tmp[128]; lua_getinfo(cL, "Sl", &ar); luaL_addstring(&b, ar.short_src); if (ar.currentline >=0) { char tmp[16]; sprintf(tmp,":%d ",ar.currentline); luaL_addstring(&b, tmp); } int i,j; for (j=1;j>-1;j-=2) { for (i=j;;i+=j) { const char * name = lua_getlocal(cL, &ar, i); if (name == NULL) break; snprintf(tmp, sizeof(tmp), "%s : %s:%d",name,ar.short_src,ar.currentline); mark_object(cL, dL, t, tmp); } } ++level; } luaL_addstring(&b, "thread: "); luaL_pushresult(&b); lua_rawsetp(dL, SOURCE, t); lua_pop(L,1); }
static void mark_userdata(lua_State *L, lua_State *dL, const void * parent, const char *desc) { const void * t = readobject(L, dL, parent, desc); if (t == NULL) return; if (lua_getmetatable(L, -1)) { mark_table(L, dL, t, "[metatable]"); } lua_getuservalue(L,-1); if (lua_isnil(L,-1)) { lua_pop(L,2); } else { mark_table(L, dL, t, "[uservalue]"); lua_pop(L,1); } }
static void mark_table(lua_State *L, lua_State *dL, const void * parent, const char * desc) { const void * t = readobject(L, dL, parent, desc); if (t == NULL) return; bool weakk = false; bool weakv = false; if (lua_getmetatable(L, -1)) { lua_pushliteral(L, "__mode"); lua_rawget(L, -2); if (lua_isstring(L,-1)) { const char *mode = lua_tostring(L, -1); if (strchr(mode, 'k')) { weakk = true; } if (strchr(mode, 'v')) { weakv = true; } } lua_pop(L,1); luaL_checkstack(L, LUA_MINSTACK, NULL); mark_table(L, dL, t, "[metatable]"); } lua_pushnil(L); while (lua_next(L, -2) != 0) { if (weakv) { lua_pop(L,1); } else { char temp[32]; const char * desc = keystring(L, -2, temp); mark_object(L, dL, t , desc); } if (!weakk) { lua_pushvalue(L,-1); mark_object(L, dL, t , "[key]"); } } lua_pop(L,1); }
int main (int argc, char **argv) { char q, action; double mat[4][4], minv[4][4], scaleFactor; double radians = 3 * (M_PI / 180); FILE *g; int cc, sign, currentObj, k, h; int increment = 15; int xcounter, ycounter, zcounter = 0; for (cc = 1; cc < argc; cc++) { g = fopen(argv[cc], "r"); //opens a file; r = read only if (g == NULL) { //if the file is empty, it will let me know printf("can't open (1)\n"); exit(1); } else { readobject(g, cc); D3d_make_identity(mat); D3d_make_identity(minv); scaleFactor = scale_n_fit(cc); D3d_translate(mat, minv, -centerx, -centery, -centerz); D3d_scale(mat, minv, scaleFactor, scaleFactor, scaleFactor); D3d_mat_mult_points(x[cc], y[cc], z[cc], mat, x[cc], y[cc], z[cc], points[cc]); // printarray(z[cc], points[cc]); } } welcome(argc - 1); scanf("%c", &q); currentObj = q - '0'; sign = 1 ; action = 't' ; if (currentObj < argc && currentObj > 0) { G_init_graphics(WIDTH, HEIGHT); while (1) { G_rgb(0, 0, 0); G_clear(); drawit(currentObj); D3d_make_identity (mat) ; D3d_make_identity (minv) ; q = G_wait_key() ; if (q == 'q') { exit(0) ; } else if (q == 'c') { sign = -sign ; } else if (q == 't') { action = q ; } else if (q == 's') { reverse = -reverse; } else if (q == 'r') { action = q ; } else if (('0' <= q) && (q <= '9')) { k = q - '0' ; if (h != currentObj) { currentObj = k; } } else if ((q == 'x') && (action == 't')) { D3d_translate (mat, minv, sign * increment, 0, 0); xcounter = xcounter + (sign * increment); } else if ((q == 'y') && (action == 't')) { D3d_translate (mat, minv, 0, sign * increment, 0); ycounter = ycounter + (sign * increment); } else if ((q == 'z') && (action == 't')) { D3d_translate(mat, minv, 0, 0, sign * increment); zcounter = zcounter + (sign * increment); } else if ((q == 'x') && (action == 'r')) { D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter); D3d_rotate_x(mat, minv, sign * radians); D3d_translate(mat, minv, xcounter, ycounter, zcounter); } else if ((q == 'y') && (action == 'r')) { D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter); D3d_rotate_y(mat, minv, sign * radians); D3d_translate(mat, minv, xcounter, ycounter, zcounter); } else if ((q == 'z') && (action == 'r')) { D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter); D3d_rotate_z(mat, minv, sign * radians); D3d_translate(mat, minv, xcounter, ycounter, zcounter); } else { printf("no action\n") ; } D3d_mat_mult_points (x[currentObj], y[currentObj], z[currentObj], mat, x[currentObj], y[currentObj], z[currentObj], points[currentObj] + 1) ; //the numpoints[currentObj]+1 is because we have stored //the center of the object at the arrays' end G_rgb(0, 0, 0); G_clear(); drawit(currentObj); } } }