Error support MaxLua

BlitzMax Forums/BlitzMax Module Tweaks/Error support MaxLua

Tricky(Posted 2012) [#1]
Basically ALL projects of mine using Lua require a modified version of MaxLua to build. The modifications make it possible to put in the Lua error message on screen (this way the users of my stuff can more easily report bugs in the Lua scripting to me, in the way MaxLua is written originally they won't see those bugs).

Here are all modifications I did to MaxLua to accomplish this:
'Slight modification by Tricky
Public
Global JBC_CatchLuaError$
Private
'End Modify

Function LuaDumpErr()
	WriteStdout "ERROR~n"
	JBC_CatchLuaError = lua_tostring( LuaState(),-1 )
	WriteStdout JBC_CatchluaError
End Function


Method lua_pushchunk()
		Local L:Byte Ptr=LuaState()

		If Not _chunk
			If luaL_loadstring( L,_source ) 
				JBC_CatchLuaError = "Error loading script :~n" + lua_tostring( L,-1 ) + "~n"
				WriteStdout JBC_CatchLuaError
				lua_pop L,1
				Return False
			EndIf
			_chunk=luaL_ref( L,LUA_REGISTRYINDEX )
		EndIf
		lua_rawgeti L,LUA_REGISTRYINDEX,_chunk
		Return True
	End Method



Basically whenever a Lua error happens the error message is now stored in a variable called 'JBC_CatchLuaError'. I placed in the 'JBC_' prefix (which was my old pseudonym for coding games and stuff) to make sure no conflicts would happen with any other module.
This way the error doesn't remain on the console for nobody to see, but now I can put up the message on screen and request my users to report the exact message to me. Makes my life (and theirs) a lot easier ^_^