Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to output to file does not work #5

Open
The-Lord-of-Owls opened this issue Jul 9, 2024 · 0 comments
Open

Attempting to output to file does not work #5

The-Lord-of-Owls opened this issue Jul 9, 2024 · 0 comments

Comments

@The-Lord-of-Owls
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant