diff options
author | Pixel <pixel@nobis-crew.org> | 2010-06-15 00:29:04 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2010-06-15 00:29:04 -0700 |
commit | ccc8261e4d48de89da4ddfe7b55e378ae0cd6f47 (patch) | |
tree | 4076c5ac46a1c1296473f307b73def6f3270c63e /lua2c.c | |
parent | 25e85e1b809ec58ecac0f2e8fe48f74836f8e131 (diff) |
Adding lua2c software...
Diffstat (limited to 'lua2c.c')
-rw-r--r-- | lua2c.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -0,0 +1,44 @@ +#include <stdio.h> + +int main(int argc, char ** argv) { + FILE * in, * out; + size_t size, i; + char * symbol; + + if (argc != 3) { + fprintf(stderr, "Usage: lua2c file_in file_out\n"); + exit(-1); + } + + if (!(in = fopen(argv[1], "rb"))) { + fprintf(stderr, "Error opening input file %s.\n", argv[2]); + perror("Opening input file"); + exit(-1); + } + + if (!(out = fopen(argv[2], "w"))) { + fprintf(stderr, "Error opening output file %s.\n", argv[3]); + perror("Opening output file"); + exit(-1); + } + + fseek(in, 0, SEEK_END); + size = ftell(in); + fseek(in, 0, SEEK_SET); + + fprintf(out, "{\nstatic const unsigned char B1[] = {"); + + for (i = 0; i < size; i++) { + if (i % 16 == 0) + fprintf(out, "\n\t"); + fprintf(out, "0x%02x, ", fgetc(in)); + } + + fprintf(out, "\n};\n\n if (luaL_loadbuffer(L, (const char *)B1, sizeof(B1), \"%s\") == 0) lua_call(L, 0, 0);\n}\n", argv[1]); + + fclose(in); + fclose(out); + + return 0; +} + |