This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gezepi's profile picture

"bios:393: Expected string" Api Woes

Started by gezepi, 23 December 2013 - 01:27 PM
gezepi #1
Posted 23 December 2013 - 02:27 PM
Hello AaP, I've recently been getting some programs I wrote all ready for the lime-light which means adding error checking. Most of my programs rely on an API of common utilities I wrote. I run my own server so I put the tools API into mods/ComputerCraft/lua/rom/shared so the programs always get the most up-to-date version. I realize this won't work with the newer versions of CC which is where my problem arises.
I've put a section at the beginning of my programs to check for the existence of the API in the shared folder. If it is not there, the files are assumed to be on the same computer as the program loading the API. This is the code I use for it:

local fileItems = "items.tbl"
local fileTools = "tools"
local filegbMenu = "gbMenu"
local filetermMenu = "termMenu"
local filept = "pt"
local pathShared = "rom/shared/"
if fs.exists(pathShared..fileTools) then --Allows use of global shared directory
  filept = pathShared..filept
  fileItems = pathShared..fileItems
  fileTools = pathShared..fileTools
  filegbMenu = pathShared..filegbMenu
  filetermMenu = pathShared..filetermMenu
end

As far as I can tell this is working as I want it.
The next piece in the puzzle is a program that loads the tools API (successfully), unloads it and then tries to load the termMenu API (unsuccesssfully). I've put some extra prints in to see if I could spot the error but nothing jumps out at me. The real killer is that when I try to load the API from the lua prompt it works fine. Here's the code:

--[[A few variable declarations and comments up here]]
local fileItems = "items.tbl"
local fileTools = "tools"
local filegbMenu = "gbMenu"
local filetermMenu = "termMenu"
local filept = "pt"
local pathShared = "rom/shared/"
if fs.exists(pathShared..fileTools) then --Allows use of global shared directory
  filept = pathShared..filept
  fileItems = pathShared..fileItems
  fileTools = pathShared..fileTools
  filegbMenu = pathShared..filegbMenu
  filetermMenu = pathShared..filetermMenu
end
os.loadAPI(fileTools)
local names = tools.names()
tools.network()
local bug = tools.bug(bolDebug)
tools.unload()
--[[A few functions that don't get called yet]]
print("Starting up")
sleep(.2)
print(filetermMenu)
print(fs.exists(filetermMenu))
print(fs.getName(filetermMenu))
--error('d')
os.loadAPI(fileTermMenu)
print(termMenu)
termMenu.new(1,1,_w, _h-1, term)
--[[Rest of the program but it never gets this far]]

The output is:

tools:Loaded
tools:Loading /rom/shared/names.tbl
tools:Rednet started on wireless modem
tools:Returning 'bug'
tools:Unloaded
Starting up
rom/shared/termMenu
true
termMenu
bios:393: Expected string

I thought it was simply a typo and I was trying to load a file with os.loadAPI that didn't exist, but the file exists (the "true").

Line 393 of bios.lua (in ComputerCraft1.53.zip\lua\) is

local sName = fs.getName( _sPath )
which I included in my test cases.

Pastebins:
SpoilerTools: http://pastebin.com/kkgiV37C
termInterface: http://pastebin.com/jFANs4S9
termMenu: http://pastebin.com/imwqJg9N

Any thoughts? Am I missing something obvious?
MKlegoman357 #2
Posted 23 December 2013 - 02:51 PM
You call your variable filetermMenu but when you load your API you use fileTermMenu.

+1 for informative post!
Edited on 23 December 2013 - 01:52 PM
gezepi #3
Posted 23 December 2013 - 03:37 PM
No way! Haha, I knew it would be something simple. When I was naming those variables I debated making them camel case or keeping the same case as the files and adding a 'file' prefix. Looks like I never quite settled the debate.

Thanks for your keen eye MKlegoman357!

Edit: Just tested it, works like a charm.
Edited on 23 December 2013 - 02:37 PM