gluac
gluac copied to clipboard
Attempting to output to file does not work
I've been trying to get this to work and I'm not sure what I'm doing wrong here. I'm attempting to implement outputting bytecode to a file, however I'm noticing that regardless of how many times I run it my output is including stuff that makes zero sense
static int lua_main(lua_State *L) {
// load our Lua file as a chunk on the stack (if filename is NULL it loads from stdin)
if ( luaL_loadfile(L, g_sInputFilename ) != 0 ) {
fprintf(stderr, "%s\n", lua_tostring(L, -1));
return 0;
}
// return early if we only want parsing
if (g_bParseOnly) {
return 0;
}
char *bytecode = 0L;
size_t len = 0;
wdata wd = {&len, &bytecode};
if (lua_bcwrite(L, write_dump, &wd, g_bStripDebug)) {
fprintf(stderr, "failed to dump bytecode\n");
return 0;
}
// output bytecode to stdout
FILE * pFile = fopen( strcat( g_sInputFilename, ".bc" ), "wb" );
fwrite( bytecode, len, sizeof( bytecode ), pFile );
fclose( pFile );
return 0;
}
This is the file I've used to test, and for what ever reason it's dumping extra irrelevant content into the file.
The only modification I've done is adding the part at the bottom to the function above in order to get the content into a file instead of just printing it test.lua_stripped.txt