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

[CC 1.80pr1] A table unserialized from a file's contents are nil?!

Started by Windows10User, 06 April 2018 - 01:29 PM
Windows10User #1
Posted 06 April 2018 - 03:29 PM
Hi, I just started making my own OS. I would like to make the bootloader depend on config files (where the 2nd stage of the loader is located, what mode to boot the OS into etc.) and I do have the basic idea of it. When I coded it all, running the 1st stage of the bootloader (startup.lua) throws an error saying "startup.lua:8: attempt to concatenate string and nil" (tells the user where the 2nd stage is located, also needed to run it) where it should say "Executing bootloader in Boot/loader.lua". Since I will need this for the OS' actual config, I am sure I will need it in the core of the OS itself! Please help!

Table (serialized and made 100% not user-made or modified):

{
  loader = "Boot/loader.lua",
  minimal = false,
}


1st stage of the loader (startup.lua):

term.clear()
term.setCursorPos(1, 1)
version = 0.1
local cfgfile = fs.open("Boot/cfg.lua", "r")
bootconfig = textutils.unserialize(cfgfile.readAll())
cfgfile.close()

print("Executing bootloader on "..bootconfig[loader])
sleep(1)
shell.run(bootconfig[loader], bootconfig[minimal])


2nd stage of the loader (Boot/loader.lua and not finished):

print("This is a nice Hello World bootloader that does nothing! (so far)")

Bomb Bloke #2
Posted 07 April 2018 - 01:44 AM
You mean either bootconfig.loader or bootconfig["loader"].