Getting a returned value from a different program with arguments

Started by Noodleman, Mar 15, 2025, 09:07 PM

Previous topic - Next topic
I am not sure how to have a program both have arguments and return a value.

I isolated the problem into a program 'test.lua'

local test = ...

local control = 'control'

print(test)
print(control)

-- do something with test

return test

When I use "print(shell.run('test.lua test'))"

I see
test
control
true
1

When I use
"print(dofile('test.lua'))"
or
"print(dofile('test.lua', 'test'))"
or
"print(dofile('test.lua', test))"

I see
nil
control
nil
1

When I use "print(dofile('test.lua test'))"

I see
lua[4]:1: File not found
Line 1
print(dofile('test.lua test'))

Can anyone tell me what it is that I am doing incorrectly?

SquidDev

You want to do loadfile("test.lua")("test") instead — dofile does not accept any arguments.
GitHub | CC:Tweaked: A ComputerCraft fork | Plethora: A peripheral mod