--[[
---------------------------------------------------------------------------
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

	This file is part of Remote Train Control.

	Remote Train Control is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Remote Train Control is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

 Home Page : http://www.silogic.com/trains/RTC_Running.html
---------------------------------------------------------------------------]]
-- Semicolons are not required in Lua code
title = "Debug Test"

require("defines");
local dbg = require("debugger") -- https://github.com/slembcke/debugger.lua
	
--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
	print(os.date("setup() %d %b %Y   %X"));
	dbg(true);	-- this breakpoint is skipped because parameter is "true". If you want
				-- to start the debugger on a certain condition, pass a value to dbg(), it works
				-- like an assert statement. The debugger only triggers if the value is nil or false.
	dbg(5 == 5);	-- will be ignored
	MyTIUNo = TIU;
	return true;		-- false=setup failed, true=setup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function loop(Engine, TIU)
	-- Calling dbg() will enter the debugger on the next executable line, in this case, right before it calls print().
	-- Once in the debugger, you will be able to step around and inspect things.
	dbg();
--[[
Debugger Commands: 
		[return] - re-run last command
		c(ontinue) - continue execution
		s(tep) - step forward by one line (into functions)
		n(ext) - step forward by one line (skipping over functions)
		p(rint) [expression] - execute the expression and print the result
		f(inish) - step forward until exiting the current function
		u(p) - move up the stack by one frame
		d(own) - move down the stack by one frame
		w(here) [line count] - print source code around the current line
		t(race) - print the stack trace
		l(ocals) - print the function arguments, locals and upvalues.
		h(elp) - print this message
		q(uit) - halt execution
--]]
	print("loop()");
	MyTIUNo = TIU;
	f1()
	return Stop("Script requested termination");		-- end the script
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup(Engine, TIU)
	-- this function is called once when the user presses the [STOP] button
	--print(os.date("cleanup()  %d %b %Y   %X"));
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function f1()
	local f1a = 5
	f2()
	end
--[[---------------------------------------------------------------------------------------]]

function f2()
	local f2a = 44
	f3()
	end
--[[---------------------------------------------------------------------------------------]]
function f3()
	local f3a = 77
	end
--[[---------------------------------------------------------------------------------------]]
