experiment with jsonrpc on server
parent
7623416772
commit
303e0d6e94
@ -0,0 +1,15 @@
|
|||||||
|
import Lean.Data.JsonRpc
|
||||||
|
|
||||||
|
-- The worker implementation roughly follows `Lean/Server/FileWorker.lean`.
|
||||||
|
|
||||||
|
|
||||||
|
#check IO.bindTask
|
||||||
|
|
||||||
|
#check Task
|
||||||
|
#check Task.CancelToken
|
||||||
|
|
||||||
|
#check EIO.mapTask
|
||||||
|
|
||||||
|
#check maybeTee
|
||||||
|
|
||||||
|
#check IO.FS.Stream.writeMessage
|
@ -1,16 +1,30 @@
|
|||||||
import GameServer.Server
|
import GameServer.Server
|
||||||
|
|
||||||
|
-- TODO: Potentially it could be useful to pass in the `gameName` via the websocket connection
|
||||||
|
|
||||||
unsafe def main (args : List String) : IO Unit := do
|
unsafe def main (args : List String) : IO Unit := do
|
||||||
|
|
||||||
|
-- Check if required arguments are given by the user
|
||||||
if args.length != 2 then
|
if args.length != 2 then
|
||||||
throw (IO.userError "Expected two arguments: The name of the game module and the path to the game project.")
|
throw (IO.userError $ "Expected two arguments:" ++
|
||||||
|
"The name of the game module and the path to the game project.")
|
||||||
let out ← IO.Process.output { cwd := args[1]!, cmd := "lake", args := #["env","printenv","LEAN_PATH"] }
|
let gameName := args[0]!
|
||||||
|
let gameDir := args[1]!
|
||||||
|
|
||||||
|
-- Determine search paths of the game project by running `lake env printenv LEAN_PATH`.
|
||||||
|
let out ← IO.Process.output
|
||||||
|
{ cwd := gameDir, cmd := "lake", args := #["env","printenv","LEAN_PATH"] }
|
||||||
if out.exitCode != 0 then
|
if out.exitCode != 0 then
|
||||||
IO.eprintln out.stderr
|
IO.eprintln out.stderr
|
||||||
else
|
return
|
||||||
|
|
||||||
|
-- Make the paths relative to the current directory
|
||||||
let paths : List System.FilePath := System.SearchPath.parse out.stdout.trim
|
let paths : List System.FilePath := System.SearchPath.parse out.stdout.trim
|
||||||
let currentDir ← IO.currentDir
|
let currentDir ← IO.currentDir
|
||||||
let paths := paths.map fun p => currentDir / (args[1]! : System.FilePath) / p
|
let paths := paths.map fun p => currentDir / (gameDir : System.FilePath) / p
|
||||||
Server.runGame (Lean.Name.mkSimple args[0]!) paths
|
|
||||||
|
-- Set the search path
|
||||||
|
Lean.searchPathRef.set paths
|
||||||
|
|
||||||
|
-- Run the game
|
||||||
|
Server.runGame gameName
|
||||||
|
Loading…
Reference in New Issue