Probelm is, when calling the text input function, I get an "attempt to call nil" error on the line where it references the global handle table.
Here's the actual text input function (Edit for clarity; this code is from my API, h[] is defined in the main program and is NOT a local variable)
function text(id,s) --id is the ID number of the monitor, s is the initial string to display so you can edit an existing string
	-- These are variables local to the API, used to prevent excessive parameter passing
	device = "monitor_" .. id
	txt = s
-----------------------
	term.redirect(h[id]) --This is the hiccup line; h[] is the global monitor handle table, and the API doesnt seem to have access to it.
-----------------------
	drawTxt() -- draws the text input screen
	dispStr() -- draws the string
	for k,v in pairs(btnsTxt) do k:draw() end --btnsTxt is a table of buttons made with my own button API; it contains a cancel, accept, backspace and shift button
	
	repeat
		local caps = btnsTxt.shift.active
		if loop() then -- loop() is an os.pullEvent that returns true if the current monitor was touched and false on any other event. mx and my are local API variables
			if button.handle(btnsTxt,mx,my) then -- button handler
				for k,v in pairs(btnsTxt) do k:draw() end
			else
				keyboard(mx,my) -- keyboard finds which letter you pressed and appends it to txt
			end -- if not handled
			dispStr()
		end -- clicked on loop
		if caps ~= btnsTxt.shift.active then drawKeyboard() end -- redraws the keyboard to reflect caps lock
	until complete == true
	
	term.restore()
	if canceled then return s else return txt end
end -- function()I thought APIs had access to global variables? If not, is there a way to give it access without converting it from an API to a dofile code chunk or passing the handle table as an argument? I tried using _G.h[ID] but that doesn't work either.
I apologize that I cannot post all of the code, but this is part of a large project and the input API alone almost exceeds the stated limit for code post length.