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

Lua via PHP

Started by HaddockDev, 15 October 2016 - 01:37 PM
HaddockDev #1
Posted 15 October 2016 - 03:37 PM
Hi all,

I have been recently messing around with CC and PHP (not together) and I have a good understanding of them.
My question is, how would you recieve server generated code to CC, then parse/run the Lua and send a response back?

I know it has been done before but never really experimented with it myself.

Thanks in advance.
Edited on 15 October 2016 - 01:39 PM
KingofGamesYami #2
Posted 15 October 2016 - 03:59 PM
First, you would need to look into the http API. You can send a GET request to your PHP server. The server should return a string of valid lua.
Once you've got the data from the server, you can use loadstring to turn it into a function, which can then be called at your leisure.
The lua side code might look something like this:

local handle = http.get( "http://www.yourphpserver.com/" )
local func, err = loadstring( handle.readAll() )
if not func then
  error( err, 0 )
end
func()
Edited on 15 October 2016 - 02:00 PM