<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: [MUD-Dev] Embedding Python --> <!--X-From-R13: "Fbqq [pYvzzrl" <ehshfNjbzongtnzrf.pbz> --> <!--X-Date: Thu, 23 Mar 2000 15:26:37 -0800 --> <!--X-Message-Id: 022b01bf951f$01b49580$0d00a8c0#wombatgames,com --> <!--X-Content-Type: text/plain --> <!--X-Reference: 20000212213017.K535#agrajag,internal --> <!--X-Reference: 20000324084404.D5514#agrajag,internal --> <!--X-Reference: 018301bf950d$489faa00$0d00a8c0#wombatgames,com --> <!--X-Reference: 20000324094234.C12791#agrajag,internal --> <!--X-Head-End--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title>MUD-Dev message, Re: [MUD-Dev] Embedding Python</title> <!-- meta name="robots" content="noindex,nofollow" --> <link rev="made" href="mailto:rufus#wombatgames,com"> </head> <body background="/backgrounds/paperback.gif" bgcolor="#ffffff" text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000"> <font size="+4" color="#804040"> <strong><em>MUD-Dev<br>mailing list archive</em></strong> </font> <br> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00721.html">Previous</a> | <a href="msg00722.html">Next</a> ] Thread: [ <a href="msg00718.html">Previous</a> | <a href="msg00292.html">Next</a> ] Index: [ <A HREF="author.html#00720">Author</A> | <A HREF="#00720">Date</A> | <A HREF="thread.html#00720">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>Re: [MUD-Dev] Embedding Python</H1> <HR> <!--X-Subject-Header-End--> <!--X-Head-of-Message--> <UL> <LI><em>To</em>: <<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>></LI> <LI><em>Subject</em>: Re: [MUD-Dev] Embedding Python</LI> <LI><em>From</em>: "Todd McKimmey" <<A HREF="mailto:rufus#wombatgames,com">rufus#wombatgames,com</A>></LI> <LI><em>Date</em>: Thu, 23 Mar 2000 17:24:59 -0600</LI> <LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> <LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI> </UL> <!--X-Head-of-Message-End--> <!--X-Head-Body-Sep-Begin--> <HR> <!--X-Head-Body-Sep-End--> <!--X-Body-of-Message--> <PRE> ----- Original Message ----- From: "Oliver Jowett" <icecube#ihug,co.nz> To: <mud-dev#kanga,nu> Sent: Thursday, March 23, 2000 3:42 PM Subject: Re: [MUD-Dev] Embedding Python > In summary, microthreads look like they can provide: > > - support for multiple (potentially a large number) of Python execution > threads, without requiring the server to be natively multithreaded. My work-around is likely horribly lazy in the eyes of a language-lawyer, but I know the system I'm going to be running it on is going to 1) be exclusive to the game itself, and 2) have at least 128mb if not 256mb of memory so I've taken some liberty in making use of what it's going to be running on. Briefly running over the setup ... As far as python itself goes, I'm partial to smaller functions than larger ones, so doing wait states is implemented a series of related pulse based callbacks. All python script hooks can be called with a single script-based python object that is definable at the time the hook is generated. Of course the object can be a list so any number of arguments can be passed as long as they're a sequence type. On top of that, the hooks into the system for all functions are done by a reference to an object id (all entities in game have a unique ID, tracked on an STL map with some caching built in for speed). Therefore if the object ceases to be, any further calls will simply be ignored or, depending on where the script hook is sitting, may be discarded entirely. So a sample conversational code might look like: def MyConversation(them, us, builderparm): if bulderparm != None: myInterfaceModule.Interpret(us, "say Welcome to my shop.") myInterfaceModule.Callback(us, 4, MyConversation, 1) else: if builderparm == 1: myInterfaceModule.Interpret(us, "say Have a look around, let me know if I can be of further help.") myInterfaceModule.Callback(us, 4, MyConversation, 2) elif builderparm == 2: ... continue conversation Since additional callbacks to the same function (or newly initialized ones) are referenced from different points in the code, the script can be in use simultaneously (or, via a series of simple checks, not executed again until the first one has finished). The above code does have a sort of 'messiness' to it, but I've also written python class wrappers around it as well if people want a different interface. Not 100% efficient, but it works and maintains the C++ code without having to resort to multiple threads (which I hate debugging) or constantly verifying that the objects you're manipulating are still hanging around in the code. In reference to some issues in the original thread: There is a code interface for c++/embedded python but the URL escapes me right now, and it serves to alleviate a lot of the reference counting headaches and doesn't require patching the actual python source at all. If I can drum it up, I'll pass it off. > .. and the implementation on top of SP is more likely to become mainstream > (and appears easier to extend) than the custom version. It'd be incredible if python were easier to embed than it already is. After the disasters of trying to write my own scripting language, the ease of embedding python as-is was a dream come true. -Todd _______________________________________________ MUD-Dev mailing list MUD-Dev#kanga,nu <A HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A> </PRE> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <HR> <!--X-Follow-Ups-End--> <!--X-References--> <UL><LI><STRONG>References</STRONG>: <UL> <LI><STRONG><A NAME="00296" HREF="msg00296.html">[MUD-Dev] Embedding Python</A></STRONG> <UL><LI><EM>From:</EM> icecube#ihug,co.nz</LI></UL></LI> <LI><STRONG><A NAME="00713" HREF="msg00713.html">Re: [MUD-Dev] Embedding Python</A></STRONG> <UL><LI><EM>From:</EM> icecube#ihug,co.nz</LI></UL></LI> <LI><STRONG><A NAME="00716" HREF="msg00716.html">Re: [MUD-Dev] Embedding Python</A></STRONG> <UL><LI><EM>From:</EM> "Todd McKimmey" <rufus#wombatgames,com></LI></UL></LI> <LI><STRONG><A NAME="00718" HREF="msg00718.html">Re: [MUD-Dev] Embedding Python</A></STRONG> <UL><LI><EM>From:</EM> Oliver Jowett <icecube#ihug,co.nz></LI></UL></LI> </UL></LI></UL> <!--X-References-End--> <!--X-BotPNI--> <UL> <LI>Prev by Date: <STRONG><A HREF="msg00721.html">Re: [MUD-Dev] Embedding C/C++</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00722.html">Re: [MUD-Dev] Embedding C/C++</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00718.html">Re: [MUD-Dev] Embedding Python</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00292.html">[MUD-Dev] OT: Soliciting advice from Canadians</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00720"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00720"><STRONG>Thread</STRONG></A></LI> </UL> </LI> </UL> <!--X-BotPNI-End--> <!--X-User-Footer--> <!--X-User-Footer-End--> <ul><li>Thread context: <BLOCKQUOTE><UL> <LI><STRONG>Re: [MUD-Dev] Embedding Python</STRONG>, <EM>(continued)</EM> <ul compact> <LI><strong><A NAME="00713" HREF="msg00713.html">Re: [MUD-Dev] Embedding Python</A></strong>, icecube <a href="mailto:icecube#ihug,co.nz">icecube#ihug,co.nz</a>, Thu 23 Mar 2000, 20:58 GMT <UL> <LI><strong><A NAME="00715" HREF="msg00715.html">Re: [MUD-Dev] Embedding Python</A></strong>, J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Thu 23 Mar 2000, 21:13 GMT </LI> <LI><strong><A NAME="00716" HREF="msg00716.html">Re: [MUD-Dev] Embedding Python</A></strong>, Todd McKimmey <a href="mailto:rufus#wombatgames,com">rufus#wombatgames,com</a>, Thu 23 Mar 2000, 21:21 GMT <UL> <LI><strong><A NAME="00718" HREF="msg00718.html">Re: [MUD-Dev] Embedding Python</A></strong>, Oliver Jowett <a href="mailto:icecube#ihug,co.nz">icecube#ihug,co.nz</a>, Thu 23 Mar 2000, 22:46 GMT <UL> <LI><strong><A NAME="00720" HREF="msg00720.html">Re: [MUD-Dev] Embedding Python</A></strong>, Todd McKimmey <a href="mailto:rufus#wombatgames,com">rufus#wombatgames,com</a>, Thu 23 Mar 2000, 23:26 GMT </LI> </UL> </LI> </UL> </LI> </UL> </LI> </ul> </LI> <LI><strong><A NAME="00292" HREF="msg00292.html">[MUD-Dev] OT: Soliciting advice from Canadians</A></strong>, Alex Oren <a href="mailto:alexo#bigfoot,com">alexo#bigfoot,com</a>, Thu 10 Feb 2000, 06:57 GMT <LI><strong><A NAME="00288" HREF="msg00288.html">[MUD-Dev] Couple of articles</A></strong>, Koster, Raph <a href="mailto:rkoster#origin,ea.com">rkoster#origin,ea.com</a>, Wed 09 Feb 2000, 17:44 GMT <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00291" HREF="msg00291.html">RE: [MUD-Dev] Couple of articles</A></strong>, Dr Richard A. Bartle <a href="mailto:richard#mud,co.uk">richard#mud,co.uk</a>, Wed 09 Feb 2000, 19:20 GMT </LI> </UL> </LI> <LI><strong><A NAME="00282" HREF="msg00282.html">[MUD-Dev] IO Speed Suggestions</A></strong>, Christopher Kohnert <a href="mailto:cjkohner#brain,uccs.edu">cjkohner#brain,uccs.edu</a>, Tue 08 Feb 2000, 19:07 GMT </LI> </UL></BLOCKQUOTE> </ul> <hr> <center> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>