This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ilikemlp123's profile picture

How to make a wireless lua prompt

Started by Ilikemlp123, 26 April 2017 - 03:47 PM
Ilikemlp123 #1
Posted 26 April 2017 - 05:47 PM
How to make a wireless lua prompt:

first: copy the base lua program and edit
to do this, simply run: "copy rom/programs/lua ./wlua"
now type edit wlua

second: locally overwrite read()
type in the following code at the very beginning:

local port = 1337	 //this is very important, it sets the port for the wireless execution, change 1337 to whatever number you want(has to be between 0 and 65535)
local modem = peripheral.find("modem")	 //this wraps the modem. you'll need this
modem.open(port)	 //this opens the previously mentioned port
local function read()	 //this is where we overwrite the read() function
local event,s,r,message,dis = os.pullEvent("modem_message")	 //this gets messages from the modem
if s == 1337 then	 //this makes sure you're on the 1337 channel to avoid errors
return message	 //tells the computer what do do
end	 //ends the if statement
end	 //ends the function
save and exit the editor.
now, for the sending side,

Sender:
create a file named wlua on the sender computer.
edit the file and type the following:

//start
local send = 1337     //sets the transmit channel, change this to the one in the first program
local rec = 137     //arguably useless
local tArgs = { ... }	 //grabs args for stuff
local modem = peripheral.find("modem") //looks for the modem, to send things
if #tArgs then print("to use wireless lua prompt, simply type 'wlua' ") //yells at you for arguing with it
else	 //else
while true do	 //loops it
local x = read()	// sets x to the given input
if  x ~= "end()" then	 //checks x for the end
modem.transmit(send,rec,x)	 //transmits your variable
else	 //else
modem.transmit(send,rec,'end()')	 //transmits the end
break end	 //breaks the loop and ends the IF statement
end	 //ends the other IF statement
end	 //ends the loop


EDIT:what i'm doing on this tutorial:
i'm overwriting the read() function with a custom function that allows me to transmit commands as a string
then, on the other computer i am transmitting the commands so that the host will execute them.
you don't need to include the comments in the code, i will put up a wlua pastebin link in the APIs and utilities
i'm sorry if this is more of a "how i did it" than a tutorial, but it's too late now
Edited on 01 December 2017 - 05:12 PM
Exerro #2
Posted 26 April 2017 - 07:48 PM
Can I just point out that anyone could transmit "shell.run'rm *'" on channel 1337 and mess up any host computer running this.

Also, the code is broken.

if not x == "end" then
Should be either

if not (x == "end") then
or

if x ~= "end" then
And if you actually want the program to stop then maybe try this:

if x == "end" then
	break
else
	-- transmit
end

At least you used locals though.

Edit: fixed forum derping the post.
Edited on 26 April 2017 - 05:54 PM
Bubbycolditz #3
Posted 13 May 2017 - 06:41 PM
Can I just point out that anyone could transmit "shell.run'rm *'" on channel 1337 and mess up any host computer running this.
Also, the code is broken.

if not x == "end" then
Should be either

if not (x == "end") then
or

if x ~= "end" then
And if you actually want the program to stop then maybe try this:

if x == "end" then
break
else
-- transmit
end

At least you used locals though.
Edit: fixed forum derping the post.

You are correct.
Gumball #4
Posted 23 May 2017 - 05:19 AM
Also, this isn't exactly a tutorial, in my opinion. Copy and pasting isn't really a tutorial, rather than just sharing your code. It'd be better if you explained this line by line, and explaining different modifications or things that can be added to each line.
Edited on 23 May 2017 - 03:19 AM