简体   繁体   中英

How do I call a Lisp function from Javascript

I wrote a program in Common Lisp (CLISP 2.49) to play connect 4 against a human player. I am using javascript and jquery for the GUI. I want to call the AIMove() function from javascript (maybe using ajax?). It takes the current state of the board (a list of 7 lists) as argument and returns a single integer (the row in which to insert the new chip). I can not figure out how to call the lisp function from the javascript code. Please help! Thanks!

I suggest that you run the Lisp code as a server and connect to the server from the browser.

I did this when I implemented a portable inspector : the browser displays the content of the lisp structure when the HTTP backend is used..

Yes, "using Ajax". But that means:

  1. Get a Lisp webserver to serve your app (a lot of folks use Hunchentoot)
  2. Now send an AJAX request from your JS client to some endpoint you listen for in the webserver with whatever parameters you need to convey the game state. The code handling that endpoint calls your Lisp function and puts the response in the body.
  3. In the client JS handler of the Ajax request you receive the Lisp result in the body of the response and process as needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM