Skip to content

Commit

Permalink
check segment fault in log_error function
Browse files Browse the repository at this point in the history
  • Loading branch information
peacalm committed Aug 26, 2024
1 parent 5e50854 commit 518afbf
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions include/peacalm/luaw.h
Original file line number Diff line number Diff line change
Expand Up @@ -1937,13 +1937,28 @@ class luaw {
std::cerr << "Lua: " << s << std::endl;
}

void log_error_in_stack(int idx = -1) const {
std::cerr << "Lua: " << lua_tostring(L_, idx) << std::endl;
const char* get_error_info_in_stack(int idx = -1) const {
return lua_tostring(L_, idx);
}

void log_error_out(int idx = -1) {
log_error_in_stack(idx);
pop();
bool log_error_in_stack(int idx = -1) const {
const char* s = get_error_info_in_stack(idx);
if (s) {
std::cerr << "Lua: " << s << std::endl;
return true;
} else {
std::cerr << "No valid error info in stack" << std::endl;
return false;
}
}

// Output error info on top on stack and pop it if it is a valid string.
bool log_error_out() {
if (log_error_in_stack(-1)) {
pop();
return true;
}
return false;
}

void log_type_convert_error(int idx, const char* to) {
Expand Down

0 comments on commit 518afbf

Please sign in to comment.