Skip to content

Commit

Permalink
Add an includeraw option
Browse files Browse the repository at this point in the history
  • Loading branch information
nashidau committed Jun 5, 2024
1 parent 646528e commit 0dc605a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/galv.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static struct predef_symbols {
#define N_PREDEF_SYMS ((int)(sizeof(predef_symbols)/sizeof(predef_symbols[0])))

static int galv_lua_include(lua_State *L);
static int galv_lua_includeraw(lua_State *L);
static int galv_lua_outraw(lua_State *L);

static int process_file(struct blam *, const char *infilename);
Expand All @@ -60,6 +61,7 @@ void galv_stack_dump(lua_State *lua,const char *msg,...);

static const luaL_Reg methods[] = {
{ "include", galv_lua_include },
{ "includeraw", galv_lua_includeraw },
{ "Oraw", galv_lua_outraw },
{ NULL, NULL },
};
Expand Down Expand Up @@ -627,6 +629,46 @@ galv_lua_include(lua_State *L) {
return 1;
}

/**
* Include another file; don't process as gvz file however
*/
static int
galv_lua_includeraw(lua_State *L) {
struct blam *blam;
const char *name;
char *buf;
struct stat st;

name = lua_tostring(L, lua_gettop(L));

lua_getglobal(L, "blam"); // FIXME: check
blam = lua_touserdata(L, -1);
lua_pop(L, 1);

{
int fd;
fd = open(name, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Unable to open '%s': %s\n", name,
strerror(errno));
return -1;
}

fstat(fd, &st);
buf = malloc(st.st_size + 1);
buf[st.st_size] = 0;
read(fd, buf, st.st_size);
close(fd);;
}

blam->write(blam, buf, st.st_size);

free(buf);

lua_pushboolean(L, 1);
return 1;
}

/**
* Send a string to blam to out to output.
*
Expand Down
2 changes: 2 additions & 0 deletions src/galvinise.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <lua.h>

#include <stdbool.h>

struct onion_response_t;

struct galv_file {
Expand Down

0 comments on commit 0dc605a

Please sign in to comment.