Skip to content

Commit a61ceaf

Browse files
committed
Use lua error reporting
1 parent 0d8b9c9 commit a61ceaf

1 file changed

Lines changed: 6 additions & 29 deletions

File tree

luaApp/src/libs/lasynlib.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,8 @@ static int asyn_read(lua_State* state, const char* port, int addr, const char* p
4545
lua_pushstring(state, output.c_str());
4646
return 1;
4747
}
48-
catch (std::runtime_error& e)
49-
{
50-
printf("asyn.read: %s\n", e.what());
51-
return 0;
52-
}
53-
catch (...)
54-
{
55-
return 0;
56-
}
48+
catch (std::runtime_error& e) { return luaL_error(state, "%s\n", e.what()); }
49+
catch (...) { }
5750

5851
return 0;
5952
}
@@ -75,18 +68,9 @@ static int asyn_write(lua_State* state, const char* data, const char* port, int
7568

7669
size_t numwrite;
7770
output.write(data, strlen(data), &numwrite);
78-
79-
return 0;
80-
}
81-
catch (std::runtime_error& e)
82-
{
83-
printf("asyn.write: %s\n", e.what());
84-
return 0;
85-
}
86-
catch (...)
87-
{
88-
return 0;
8971
}
72+
catch (std::runtime_error& e) { return luaL_error(state, "%s\n", e.what()); }
73+
catch (...) { }
9074

9175
return 0;
9276
}
@@ -156,15 +140,8 @@ static int asyn_writeread(lua_State* state, const char* data, const char* port,
156140
lua_pushstring(state, output.c_str());
157141
return 1;
158142
}
159-
catch (std::runtime_error& e)
160-
{
161-
printf("asyn.writeread: %s\n", e.what());
162-
return 0;
163-
}
164-
catch (...)
165-
{
166-
return 0;
167-
}
143+
catch (std::runtime_error& e) { return luaL_error(state, "%s\n", e.what()); }
144+
catch (...) { }
168145

169146
return 0;
170147
}

0 commit comments

Comments
 (0)