Browse Source

add:启用dbg

Dozingfiretruck 4 years ago
parent
commit
bd4a82c245
2 changed files with 5 additions and 5 deletions
  1. 3 3
      luat/modules/luat_lib_dbg.c
  2. 2 2
      luat/modules/luat_main.c

+ 3 - 3
luat/modules/luat_lib_dbg.c

@@ -190,7 +190,7 @@ static int value_to_dbg_json(lua_State* L, const char* name, char** buff, size_t
     cJSON *cj = cJSON_CreateObject();
 
     cJSON_AddStringToObject(cj, "name", name);
-    cJSON_AddStringToObject(cj, "type", lua_typename(L, lua_type(L, -1)));
+    cJSON_AddStringToObject(cj, "type", lua_typename(L, -1));
 
     switch (ltype)
     {
@@ -218,10 +218,10 @@ static int value_to_dbg_json(lua_State* L, const char* name, char** buff, size_t
     }
     char* str = cJSON_Print(cj);
     size_t slen = strlen(str);
-    *buff = luat_heap_malloc(slen);
+    *buff = luat_heap_malloc(slen+1);
     if (*buff == NULL)
         return -2;
-    memcpy(*buff, str, slen);
+    memcpy(*buff, str, slen+1);
     cJSON_Delete(cj);
     return 0;
 #else

+ 2 - 2
luat/modules/luat_main.c

@@ -81,8 +81,8 @@ static int pmain(lua_State *L) {
 #endif
 
 #ifdef LUAT_USE_DBG
-    //extern void luat_debug_hook(lua_State *L, lua_Debug *ar);
-    //lua_sethook(L, luat_debug_hook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE, 0);
+    extern void luat_debug_hook(lua_State *L, lua_Debug *ar);
+    lua_sethook(L, luat_debug_hook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE, 0);
     // 寻找dbg_init.lua, 里面有初始化代码
     if (luat_search_module("dbg_init", filename) == 0) {
         luaL_dofile(L, filename);