Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Valentin Long

error using string.sub(stringObject), "attempt to get length of a number value"

Question

im trying to make a small custom Os. i managed to get the BIOS working and now im trying to load libraries to the lua enviroment (OpenOS does the same from my understanding)

i have a function that iterates over all the files on /lib/core and loads them. however im getting an error that i did not manage to solve. Here is the first part of the function:

clarification: as im working almost at bios level, i dont have access to some functions like print(). so i use error() to print a message in screen
 

 --loading libraries in /lib/core
  do
    for _, object in pairs(component.invoke(addr, "list", "/lib/core")) do --equivalent to component.filesystem.list("/lib/core") then object becomes a file or directory in /lib/core for each iteration

	  --if i call error(object) at this point the message reads the correct content of object

      if not component.invoke(addr, "isDirectory", "/lib/core/" .. object) then --if object is not a directory (a file) 
        local lib, err = loadfile("/lib/core/" .. object) --calls loadlib. this function reads the file and returns a function lib. when lib is called it returns the table corresponding to the library loaded

		--at this point when i call error(type(object)) i get that object is a string

        local name = string.sub(object, 1, #object - 4) --here i get the error "attempt to get length of a number value"  sugesting that object has now became a number

--[...]

 

i have been thinkering for some time now, however i didnt manage to solve the error. Thanks

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.