Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I developed a two-player iPhone board game. Computer players (AI) can either be local (in the game code) or remote running on a server. In the 2nd case, both client and server code are coded in Lua. On the server the actual AI code is separate from the TCP socket code and coroutine code (which spawns a separate instance of AI for each connecting client).

I want to be able to further isolate the AI code so that that part can be a module coded by anyone in their language of choice. How can I do this? What tecniques/technology would enable communication between the Lua TCP socket/coroutine code and the AI module?

share|improve this question
    
swig.org comes to mind.. –  Jari Komppa Mar 15 '11 at 10:33
    
swig is c/c++ to other languages. Lua to other languages needs a different route. –  David Young Mar 15 '11 at 17:17

2 Answers 2

A socket based messaging scheme can be used to allow any arbitrary language to interact with the AI. You could use binary based messages, xml, text, etc. Just clearly define what the message format is and what messages you will send and receive.

This technique works relatively well for light to modest communication handling. There is a latency penalty associated with it of course, but since your game is a board game style it doesn't have to run in real-time.

share|improve this answer
    
I'm already using sockets to get the AI's move from the AI server to the iOS client. Everything is in Lua. I want to know how an AI routine, coded in Python, for example (on the server) could communicate with the Lua socket routine (on the server). For example, the Python AI sends its move to the Lua socket routine which then uses the TCP socket to relay the move to the iOS client. –  Tokyo Dan Mar 16 '11 at 0:38
    
Answered below but socket to socket communication can be used to communicate between two processes or programs on the same computer. In the same manner as two programs communicating over the internet. Except you don't need all that TCP/IP handling. –  David Young Mar 16 '11 at 1:13

For any language X, you can't know what interop feature it does or does not have- no language is expected to provide any interoperation features. The most reliable is C-style, as that is (almost certainly) what your OS uses, although this doesn't mean that the language actually exposes it.

Perhaps the most independent would be using a named pipe provided by the OS and sending through say, XML messages. However, this is a tad extreme- most encapsulation schemes stop short of encapsulating the authoring language.

share|improve this answer
    
Pipes are a useful approach especially if you want something to test out quick and dirty. It isn't very scalable though and much slower than direct socket to socket communication. –  David Young Mar 15 '11 at 22:54
    
Maybe I'm missing something. I'm new to this. I thought sockets were used to get info from one computer to another computer somewhere on the net. Can sockets also be used for communication between two programs/processes/coroutines running on the same computer? –  Tokyo Dan Mar 16 '11 at 0:41
    
Yep! you are basically communicating over a localhost socket which won't actually route outside the ethernet card. With socket communication you could be talking to another program on the same computer or another program on a different computer. It's handled exactly the same. –  David Young Mar 16 '11 at 1:10
    
Thanks. Even if this is possible the non-Lua AI routine would have to code socket communication routines. I want to get away from this. I just want the non-Lua AI to send a string like "Move P1 to X Y" to my Lua socket code on the server. The Lua socket code will relay the string to the iOS client. –  Tokyo Dan Mar 16 '11 at 1:17
    
You might try using Pipes directly then. Let your server side Lua spawn a child process which is your non-Lua AI program. You can communicate with the child process through it's In and Out pipes. lua-users.org/wiki/ExtensionProposal –  David Young Mar 16 '11 at 1:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.