Advertisement
Starkkz

Lua Error traceback

Jun 23rd, 2015
3,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function PRINT_ERROR_TO_CS2D_CONSOLE(ERROR:String)
  2.     Print "Lua Error: " +  Error
  3. EndFunction
  4.  
  5. Function lua_traceback:Int(L:Byte Ptr)
  6.     If Not lua_isstring(L, 1) Then
  7.         Return 1
  8.     EndIf
  9.     lua_getfield(L, LUA_GLOBALSINDEX, "debug")
  10.     If Not lua_istable(L, -1) Then
  11.         lua_pop(L, 1)
  12.         PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1))
  13.         Return 1
  14.     EndIf
  15.     lua_getfield(L, -1, "traceback")
  16.     If Not lua_isfunction(L, -1) Then
  17.         lua_pop(L, 2)
  18.         PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1))
  19.         Return 1
  20.     EndIf
  21.     lua_pushvalue(L, 1)
  22.     lua_pushinteger(L, 2)
  23.     lua_call(L, 2, 1)
  24.     PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1))
  25.     Return 1
  26. EndFunction
  27.  
  28. Function luaL_dofile2:Int(L:Byte Ptr, Path:String)
  29.     lua_pushcfunction(L, lua_traceback)
  30.     luaL_loadfile(L, Path)
  31.     Return lua_pcall(L, 0, 0, lua_gettop(L) - 1)
  32. EndFunction
  33.  
  34. Function lua_pcall2:Int(L:Byte Ptr, nargs:Int, nresults:Int)
  35.     lua_pushcfunction(L, lua_traceback)
  36.     lua_pcall(L, nargs, nresults, 0)
  37.     Return lua_pcall(L, 0, 0, lua_gettop(L) - 1)
  38. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement