file = fs.open("/rom/programs/edit","r")
load(file.readAll())("example")
This give me a string error. The same problem with other programs. Have anybody a solution for this? In the programm who I'm need it, the code is just a string and not are file like the example.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
load() with large code
Started by Wilma456, 18 November 2016 - 05:32 PMPosted 18 November 2016 - 06:32 PM
load() does not work with large code. For example:
Posted 18 November 2016 - 06:34 PM
you can do loadfile(path) i believe…
Posted 18 November 2016 - 07:31 PM
Maybe the code is malformed in some way? It should give you more than just a "string error".
Try using load instead of loadstring
Try using load instead of loadstring
Posted 19 November 2016 - 12:17 AM
He did.Maybe the code is malformed in some way? It should give you more than just a "string error".
Try using load instead of loadstring
I think the problem is the environment.
Shell is using a special environment to run programs with the shell and multishell API.
For some reasons, the shell API isn't global, so you have to add the API into the environment:
load(sFile, 'edit', setmetatable({shell = shell, multishell = multishell}, {__index = _G}))
Note, you need this code just if you wanna use the shell API.
Edited on 18 November 2016 - 11:18 PM
Posted 19 November 2016 - 02:15 AM
I know nothing about load, but in the code given by OP there are two discreet sets of brackets on the load line - is that even valid for load? To me it appears that he's attempting to load file.readAll() then he has "example" enclosed in a separate set of brackets.
Posted 19 November 2016 - 02:56 AM
<p>
Load returns a function (which is the string loaded as code) which you either save in some variable or execute directly.
I know nothing about load, but in the code given by OP there are two discreet sets of brackets on the load line - is that even valid for load? To me it appears that he's attempting to load file.readAll() then he has "example" enclosed in a separate set of brackets.
Load returns a function (which is the string loaded as code) which you either save in some variable or execute directly.
local function foo() return function(bar) print(bar) end end foo()("bar") --> prints bar
Damn mobile Firefox. Messes up the code…Edited on 19 November 2016 - 01:58 AM
Posted 19 November 2016 - 03:12 AM
Oh, wow - I didn't know that was possible - thanks, H4X0RZ, I learned something new today :)/>
Posted 19 November 2016 - 11:15 AM
<p>
Btw, this allows you to do some funny stuff :D/>Oh, wow - I didn't know that was possible - thanks, H4X0RZ, I learned something new today :)/>
I "like" "pancakes"
is (theoretically) valid syntax: it's a function taking one string as parameter, returning another function with yet another string as parameter.Edited on 19 November 2016 - 10:15 AM