LUALIB_API int luaL_getn (lua_State *L, int t) { int n; t = abs_index(L, t); lua_pushliteral(L, "n"); /* try t.n */ lua_rawget(L, t); if ((n = checkint(L, 1)) >= 0) return n; getsizes(L); /* else try sizes[t] */ lua_pushvalue(L, t); lua_rawget(L, -2); if ((n = checkint(L, 2)) >= 0) return n; return (int)lua_objlen(L, t); }
LUALIB_API void luaL_setn (lua_State *L, int t, int n) { t = abs_index(L, t); lua_pushliteral(L, "n"); lua_rawget(L, t); if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ lua_pushliteral(L, "n"); /* use it */ lua_pushinteger(L, n); lua_rawset(L, t); } else { /* use `sizes' */ getsizes(L); lua_pushvalue(L, t); lua_pushinteger(L, n); lua_rawset(L, -3); /* sizes[t] = n */ lua_pop(L, 1); /* remove `sizes' */ } }
int main(int argc, char* argv[]) { int x; int y; int size; float* values; char file_name[1024]; char new_file_name[1024]; printf("Hello \n"); printf("This is version 0.01 Feel free to change and mess it up however you want \n"); printf("So....you have some files which should be converted to a .CVS format?\n Are your files ....."); printf("\n\n\t1) Seperated by a tab? \n\t2) Seperated by a newline ?\n\n\n Please choose 1 or 2\n"); x = getinfos(); y = getoutinfo(); size = getsizes(); values = (float*) malloc(sizeof(float) * (size +1)); entername(); scanf("%99s", &file_name[0]); printf("%s", file_name); switch(x) { case 1: values = read_double_tab(file_name,size); break; case 2: values = read_double_new_line(file_name,size); break; } printf("\n Please name the new file like this:\n Example.CVS \n"); scanf("%99s", &new_file_name[0]); switch(y) { case 1: write_double_one_line(new_file_name,values, size); break; case 2: write_double_one_column(new_file_name,values, size); break; } free(values); }
int luaL_getn (lua_State *L, int t) { int n; t = abs_index(L, t); lua_pushliteral(L, "n"); /* try t.n */ lua_rawget(L, t); if ((n = checkint(L, 1)) >= 0) return n; getsizes(L); /* else try sizes[t] */ lua_pushvalue(L, t); lua_rawget(L, -2); if ((n = checkint(L, 2)) >= 0) return n; for (n = 1; ; n++) { /* else must count elements */ lua_rawgeti(L, t, n); if (lua_isnil(L, -1)) break; lua_pop(L, 1); } lua_pop(L, 1); return n - 1; }