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

How to run string as a program(EEPROM)

Question

I am building an OS and i am not going to use the filesystem library.  I am going to write my own filesystem for unmanaged drives.  To boot i need to be able to run programs.  The default libraries will not support my custom filesystem how can i run programs?

Is is possible to compile and run a string as a program using EEPROM accessible  libraries?

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

load is a function that's a part of the Lua standard library. This means that you can use it even in EEPROM programs.

The signature of the function is load(chunk[, chunkname[, mode[, env]]]).

  • The first argument is either a string of code you want to run, or an iterator function that returns a Lua code.
  • The second argument is the name of the chunk. It's used for error messages.
  • The third argument is the mode: either "bt" (both binary and text), "t" (text), and "b" (binary). In standard Lua implementations, "b" mode is used to load pre-compiled code returned by string.dump. In OpenComputers, however, this feature is disabled by default for security reasons.
  • The fourth argument is the environment to run the code with. The environment is a table that contains some values that can be used in the code. If you make {hello=function(name) print("Hello, " .. tostring(name) .. "!") end} the environment, the hello function can be called from within the code: load("hello('world')", nil, nil, {hello=function(name) print("Hello, " .. tostring(name) .. "!") end}) prints "Hello, world!" when run.

load doesn't run the code. It checks it for syntax errors, and returns a function that, when called, runs the code. Here's an example.

load([[
  print("Hello")
  local x = math.sin(45 / 180 * math.pi)
  print("The sine of 45° is " .. x)
]])()

--> Hello
--> The sine of 45° is 0.70710678118655
Link to post
Share on other sites

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.