Created
April 29, 2012 21:17
-
-
Save mischief/2553298 to your computer and use it in GitHub Desktop.
This file contains 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 void luafmt(void *data, const char *fmt, ...) { | |
char *buf; | |
lua_State *L = (lua_State *) data; | |
va_list vl; | |
va_start(vl,fmt); | |
int size = vsprintf(NULL, fmt, vl); | |
buf = malloc(size * sizeof(char)); | |
if(!buf) luaL_error(L, "luafmt: no memory"); | |
vsprintf(buf, fmt, vl); | |
lua_pushstring(L, buf); | |
free(buf); | |
} | |
static int lua_cpuid (lua_State *L) { | |
lua_newtable(L); /* creates a table */ | |
int size1 = lua_gettop(L); // store first size | |
// cpu_info_format(&base_cpuid, luafmt, L); //format shit | |
luafmt((void *) L, "%s", "1 foo"); | |
luafmt((void *) L, "%s", "2 bar"); | |
int size2 = lua_gettop(L); | |
// makes a string?? | |
for(int i = size2; i < size1; --i) { | |
lua_rawseti(L, 1, i); | |
} | |
// makes a table, but wrong order | |
/* | |
for(int i = size2; i > size1; --i) { | |
lua_rawseti(L, 1, i); | |
} | |
*/ | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment