@@ -112,8 +112,7 @@ static void mf_register(lua_State *L) {
112112
113113static jmp_buf luawrap_panic_jump;
114114
115- bool luawrap_overtime = false ;
116- uint32_t luawrap_start_ts = 0 ;
115+
117116
118117/* custom panic handler */
119118static int luawrap_panic (lua_State *L)
@@ -123,11 +122,16 @@ static int luawrap_panic(lua_State *L)
123122 return 0 ;
124123}
125124
125+ /*
126+ //------------------------
127+ // lua CPU time watchdog
128+ //------------------------
129+ uint32_t luawrap_start_ts = 0;
130+ bool luawrap_overtime = false;
131+
126132//debug handler, called every time 1000 lines are executed
127133static void luawrap_hook(lua_State *L, lua_Debug *ar) {
128- return ;
129-
130- Serial.printf (" luawrap_hookcnt dt=%u\n " , micros () - luawrap_start_ts);
134+ //Serial.printf("luawrap_hookcnt dt=%d\n", (int)(micros() - luawrap_start_ts));
131135 if(micros() - luawrap_start_ts < 1000000) return;
132136
133137 luawrap_overtime = true;
@@ -139,7 +143,6 @@ static void luawrap_hook(lua_State *L, lua_Debug *ar) {
139143 luaL_error(L, "Exceeded CPU time");
140144}
141145
142- /*
143146static void luawrap_reset_loop_overtime(lua_State *L) {
144147 luawrap_overtime = false;
145148 // reset the hook to clear the counter
@@ -194,13 +197,16 @@ void luawrap_run(const char* code) {
194197 // register mf table and global lua functions
195198 mf_register (L);
196199
197- // execute
198- // luawrap_reset_loop_overtime(L); //optional
200+ // optional cpu time watchdog
201+ // luawrap_reset_loop_overtime(L);
202+
203+ // execute lua script
199204 if (luaL_dostring (L, code) == LUA_OK) {
200205 lua_pop (L, lua_gettop (L)); // Pop the return value
201206 }else {
202207 const char *err = luaL_checkstring (L, -1 );
203208 Serial.printf (" LUA: ERROR: %s\n " , err);
204209 }
210+
205211 lua_close (L);
206212}
0 commit comments