Skip to content

Commit

Permalink
add bee_assert.c
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Feb 8, 2024
1 parent 765aa99 commit 91aae62
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
20 changes: 20 additions & 0 deletions 3rd/lua/bee_assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "bee_assert.h"

void _bee_lua_assert(const char* message, const char* file, unsigned line) {
fprintf(stderr, "(%s:%d) %s\n", file, line, message);
fflush(stderr);
abort();
}

void _bee_lua_apicheck(lua_State* L, const char* message, const char* file, unsigned line) {
fprintf(stderr, "(%s:%d) %s\n", file, line, message);
fflush(stderr);
if (!lua_checkstack(L, LUA_MINSTACK)) {
abort();
}
luaL_traceback(L, L, 0, 0);
fprintf(stderr, "%s\n", lua_tostring(L, -1));
fflush(stderr);
lua_pop(L, 1);
abort();
}
6 changes: 6 additions & 0 deletions 3rd/lua/bee_assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "lauxlib.h"

void _bee_lua_assert(const char* message, const char* file, unsigned line);
void _bee_lua_apicheck(lua_State* L, const char* message, const char* file, unsigned line);
20 changes: 2 additions & 18 deletions 3rd/lua/lprefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,8 @@

#if !defined(NDEBUG)

#include "lauxlib.h"
inline void _bee_lua_assert(const char* message, const char* file, unsigned line) {
fprintf(stderr, "(%s:%d) %s\n", file, line, message);
fflush(stderr);
abort();
}
inline void _bee_lua_apicheck(lua_State* L, const char* message, const char* file, unsigned line) {
fprintf(stderr, "(%s:%d) %s\n", file, line, message);
fflush(stderr);
if (!lua_checkstack(L, LUA_MINSTACK)) {
abort();
}
luaL_traceback(L, L, 0, 0);
fprintf(stderr, "%s\n", lua_tostring(L, -1));
fflush(stderr);
lua_pop(L, 1);
abort();
}
#include "bee_assert.h"

# if defined(lua_assert)
# undef lua_assert
# endif
Expand Down
1 change: 1 addition & 0 deletions 3rd/lua/onelua.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#include "ltablib.c"
#include "lutf8lib.c"
//#include "linit.c"
#include "bee_assert.c"
#endif

/* lua */
Expand Down

0 comments on commit 91aae62

Please sign in to comment.