Forum
News CS2D Beta 0.1.2.6I just found out a method to get a better tracing for Lua errors, it might be useful for CS2D. Maybe you could apply it to the hotfix, so it becomes easier to fix broken scripts. I just built this code and tested it. It's necessary to replace PRINT_ERROR_TO_CS2D_CONSOLE with the actual function that prints those errors.
And if you're using:
luaL_dofile, luaL_loadfile or any other load function with luaL_dofile2
lua_pcall with lua_pcall2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Function PRINT_ERROR_TO_CS2D_CONSOLE(ERROR:String) 	Print "Lua Error: " + Error EndFunction Function lua_traceback:Int(L:Byte Ptr) 	If Not lua_isstring(L, 1) Then 		Return 1 	EndIf 	lua_getfield(L, LUA_GLOBALSINDEX, "debug") 	If Not lua_istable(L, -1) Then 		lua_pop(L, 1) 		PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1)) 		Return 1 	EndIf 	lua_getfield(L, -1, "traceback") 	If Not lua_isfunction(L, -1) Then 		lua_pop(L, 2) 		PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1)) 		Return 1 	EndIf 	lua_pushvalue(L, 1) 	lua_pushinteger(L, 2) 	lua_call(L, 2, 1) 	PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1)) 	Return 1 EndFunction Function luaL_dofile2:Int(L:Byte Ptr, Path:String) 	lua_pushcfunction(L, lua_traceback) 	If luaL_loadfile(L, Path) Then 		PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1)) 	Else 		lua_pcall(L, 0, 0, lua_gettop(L) - 1) 	EndIf EndFunction ' Notice that I removed the errfunc:Int argument here Function lua_pcall2:Int(L:Byte Ptr, nargs:Int, nresults:Int) 	lua_pushcfunction(L, lua_traceback) 	If lua_pcall(L, nargs, nresults, 1) Then 		PRINT_ERROR_TO_CS2D_CONSOLE(lua_tostring(L, -1)) 	Else 		lua_pcall(L, 0, 0, lua_gettop(L) - 1) 	EndIf EndFunction
So I tried this test code.
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
function a() 	error("testing") end function b() 	a() end function c() 	b() end
And it prints the error + traceback.
1
2
3
4
5
6
2
3
4
5
6
Lua Error: test.lua:2: testing stack traceback: 	[C]: in function 'error' 	test.lua:2: in function 'a' 	test.lua:6: in function 'b' 	test.lua:10: in function <test.lua:9>
It works with the Lua function debug.traceback, so if someone ever removes that function in the Lua code. I made sure that it would at least print the first line from the error.
Edit: If you could apply that asap to all versions of CS2D and cs2d_dedicated it would also be very helpful because there are still remains of LuaJIT-2.0.0 beta-4, and most stack overflow errors were fixed from LuaJIT-2.0.0 beta-6 to LuaJIT-2.0.4. At least windows cs2d_dedicated is still beta 4.
edited 1×, last 23.06.15 05:46:32 pm
Also this means a shitload of replacement work for me with a super crappy IDE
1. Copy
2. Test
3. Approve
Those functions I gave were broken, I had to make two new ones.
But if there's a god existing somewhere there, I hope he blesses us with stability over LuaJIT 2.0.3, and no random stack overflow(s).
First of all, @ DC: THANK YOU! LuaJIT (+FFI) would really open up a lot of potential and further advance the life of this game. I truly appreciate your efforts with this update. Same to you @ Starkkz: for helping him out.
And second, to those with issues, no one told you that you had to update. Just because it's new doesn't mean you have to use it. Feel free to use the previous version until the new one suits you. Be patient and provide helpful feedback.