ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: Noodleman on Mar 15, 2025, 09:07 PM

Title: Getting a returned value from a different program with arguments
Post by: Noodleman on Mar 15, 2025, 09:07 PM
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?
Title: Getting a returned value from a different program with arguments
Post by: SquidDev on Mar 16, 2025, 08:57 AM
You want to do loadfile("test.lua")("test") instead — dofile does not accept any arguments.