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

Dynamic API Call

Started by JavaPortals, 19 February 2014 - 04:02 AM
JavaPortals #1
Posted 19 February 2014 - 05:02 AM
Hey,

So i'm trying to do a simple OS system for me and some friends, but the problem is. Not all of us are english speaking,
So I wanted to add a language function to it. But I went into a problem. Dynamic API calling. I know that when you use os.loadAPI it returns true on success and false on error, and that the API is loaded to the file name. But, what if the file name is stored in a variable? Ex: The language file name is da_DK which is stored in the variable languageFile. if I then do
os.loadAPI(languageFile) then I would have to do da_DK.get() to get the language table. but if the languageFile is en_US then I would have to do en_US.get(). How would I get around this?

- Roe
Lyqyd #2
Posted 19 February 2014 - 10:13 AM
Don't load up language files as APIs. Open the file, read the information (probably into a translation table) and close it again.
JavaPortals #3
Posted 19 February 2014 - 12:09 PM
Don't load up language files as APIs. Open the file, read the information (probably into a translation table) and close it again.

Alright, I created a new file holding my language table. I'm using the fs.open("file here", "mode") function to open and then the .readAll() to read. Last, I use the textutils.unserialize (The file is serialized) to convert the data. But i'm just getting a string and not a table?
Bomb Bloke #4
Posted 19 February 2014 - 08:27 PM
Hard to comment on that without seeing the contents of the file, or your code.

To guess, you're doing something like this:

local myFile = fs.open("file here","r")
local strings = myFile.readAll()
myFile.close()

textutils.unserialize(strings)

… instead of:

local myFile = fs.open("file here","r")
local strings = myFile.readAll()
myFile.close()

strings = textutils.unserialize(strings)
JavaPortals #5
Posted 21 February 2014 - 02:00 AM
Hard to comment on that without seeing the contents of the file, or your code.

To guess, you're doing something like this:

local myFile = fs.open("file here","r")
local strings = myFile.readAll()
myFile.close()

textutils.unserialize(strings)

… instead of:

local myFile = fs.open("file here","r")
local strings = myFile.readAll()
myFile.close()

strings = textutils.unserialize(strings)

Hey, Sorry about that. But I actually did the last approach from the beginning, but i'm still getting a string.
http://puu.sh/74lPU.png