Skip to content

Commit

Permalink
Be a bit more verbose on error.
Browse files Browse the repository at this point in the history
  • Loading branch information
nashidau committed Mar 18, 2024
1 parent 8b55b23 commit 646528e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ project(Galvinise VERSION 0.2 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_compile_options(-Wall -Wextra)

include(FindPkgConfig)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_library(galvinise galv.c diskslurp.c blam_buf.c blam_direct.c blam_writev.c
list(APPEND EXTRA_LIBS galvinise)



add_executable(galv main.c)
target_link_libraries(galv PUBLIC galvinise ${TALLOC_LDFLAGS} ${CHECK_LDFLAGS} ${LUA_LDFLAGS})

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PREFIX=/usr/local
.PHONY:tags

ifndef CFLAGS
CFLAGS=-Wall -O2 -g3 -std=c99
CFLAGS=-Wall -O2 -g3 -std=c2x
endif

include ../config.mk
Expand Down
1 change: 1 addition & 0 deletions src/check.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <check.h>
#include <stdarg.h>
#include <talloc.h>

#include "galv_check.h"
Expand Down
25 changes: 24 additions & 1 deletion src/galv.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,25 @@ walk_symbol(const char *sym, int len) {
return 0;
}

__attribute__((noreturn)) static void
handle_lua_error(lua_State *L, int errcode) {
switch (errcode) {
case LUA_ERRRUN:
fprintf(stderr, "Lua runtime error: %s\n", lua_tostring(L, -1));
break;
case LUA_ERRMEM:
fprintf(stderr, "Lua memory error: %s\n", lua_tostring(L, -1));
break;
case LUA_ERRERR:
fprintf(stderr, "Lua error handling error: %s\n", lua_tostring(L, -1));
break;
case LUA_ERRSYNTAX:
fprintf(stderr, "Lua syntax error: %s\n", lua_tostring(L, -1));
break;
}
exit(1);
}

// FIXME: Should get the line number or something.
static int
eval_lua(struct blam *blam, const char *block, int len) {
Expand All @@ -566,7 +585,11 @@ eval_lua(struct blam *blam, const char *block, int len) {
exit(1);
}
#endif
lua_pcall(L, 0, 1, 0); // FIXME: Should use LUA_MULTRET
int rv = lua_pcall(L, 0, 1, 0); // FIXME: Should use LUA_MULTRET
if (rv != 0){
handle_lua_error(L, rv);
}

if (lua_isstring(L, -1)) {
blam->write_string(blam, lua_tostring(L, -1));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define _GNU_SOURCE 1
//#define _GNU_SOURCE 1

#include <assert.h>
#include <ctype.h>
Expand Down

0 comments on commit 646528e

Please sign in to comment.