lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Dirk Laurie once stated:
> I have added an essay on protected calls to my collection of Lua Notes.
> 
> https://github.com/dlaurie/lua-notes
> 
> The topics in the README are clickable, but once in, you can't get
> back. Better open them in a new tab.
> 
> As usual, the notes are for my own use, inspired by discovering the
> depths of my ignorance when trying to use lua_pcall properly.
> 
> Comments, especially if phrased as suggestions for improvement, are welcome.

  You can also supply a function to collect more information, such as a
stack dump.  I've done this as work and it helps.  The way I did it looks
something like this:

	---[ in some Lua file that's loaded ]---

	function stackdump(...)
	  --[[ 
		dump to syslog() the following:
		* parameters
		* for i = 1 , 10 do syslog(debug.getinfo(i,"Sl")) end
	   --]]
	  return ...
	end

and in C (usually in main()):

	lua_getglobal(L,"stackdump");
	lua_pushcfunction(L,program_main);
	result = lua_pcall(L,0,LUA_MULTRET,-2);
	if (result != 0)
	{
	 ...
	}

 -spc