|
sabman Novice
Joined: 17 Aug 2007 Posts: 34
|
Posted: Tue Nov 06, 2007 4:46 am
PHPScript & CMUD |
I have a question for those who may be able to answer it.
I've set up PHP5 along with the php5activescript.dll on my computer, since I'm far, far more comfortable with PHP over Lua.
My question is this...what do I need to do to access functions like print() and such?
I assume it's a variable name, and I can't seem to find it. I tried $world->print("test"), but that doesn't seem to work. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Nov 06, 2007 5:45 am |
You can't really do that. The beauty of Lua was that I could override it's functions so that I could make "print" output text to the MUD window. In PHP, the echo routine will output to "standard output" which isn't defined in CMUD, so there isn't any easy way to access the MUD output window.
From Window's Script Host languages, such as ActivePHP, you can only use the COM interface for CMUD. CMUD defines a global objects called "cmud" (the Application object) and "sess" (the current session window). So see the COM Server documentation for zMUD and you can usually just change any reference of zMUD to cmud.
For example, doing
$cmud->EchoStr("hello world",2)
should display the string "hello world" in the CMUD window. Anyway, the interface for WSH scripting languages is pretty limited, and they are typically much slower than either zScript, or especially Lua. If you want more efficient scripts, I really can't recommend the WSH languages, and it's hard to share your scripts with others because they might not have ActivePHP installed.
And honestly, since both PHP and Lua have C-like syntax, it's really not hard to learn Lua at all. My background was in PHP and I picked up Lua easily in just a couple of days. You might want to check out Fang's Lua Tutorial. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Nov 06, 2007 10:42 am |
Fang's incomplete Lua tutorial. For now, and especially since you have experience, you may find Programming in Lua more useful.
|
|
|
|
sabman Novice
Joined: 17 Aug 2007 Posts: 34
|
Posted: Tue Nov 06, 2007 12:17 pm |
I have used Lua before. I was using MUSH before I decided to give CMUD a try, and all my MUSH scripts are in Lua. Also, my new healing system has been started in Lua, although through MudBot. I just don't like how Lua handles tables, the fact that it's classless, and such.
So it's not so much I don't know how to use Lua, I've just not caught onto the bandwagon of everyone using it. Had I better knowledge of C/C++ I'd choose that, but I'm not going to learn more on it until I get to Full Sail.
Well, thanks for the help. I'll stick to what I've been doing, then. Once CMUD gets more stable, I may try to use just it, but for now it'll be a IMTS/Lua back end with a CMUD front, that way I'm not crippled if a new Beta crashes my setup. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Nov 07, 2007 1:23 am |
Zugg wrote: |
The beauty of Lua was that I could override it's functions so that I could make "print" output text to the MUD window. In PHP, the echo routine will output to "standard output" which isn't defined in CMUD, so there isn't any easy way to access the MUD output window. |
Well, displaying stuff to the MUD window is not actually something that most scripts do, and in any case it's unclear what you would mean by "print". Is that the equivalent of #ECHO, #SAY, #SHOW or what? Why not just use those commands from Lua directly without overriding print? If it's too much to type the full command, you can just create a Lua function called p(text-to-display), or something, to wrap the full command. (Or at least I imagine you can do this, without actually knowing any Lua myself.) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Nov 07, 2007 1:51 am |
You can. You could even change the definition of print so that it called whichever of those functions you want. But of course, the documentation for the Lua interface will explain exactly what print does. And since print wouldn't be doing anything anyway, it adds something while not stopping you from doing anything. Can't be a bad thing.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Nov 07, 2007 5:53 am |
Lua programmers are just used to using the Lua "print" command to output text, so it's natural to redefine it to display text to the output window (like #echo, #say, etc). Yes, you can still call the CMUD command directly using zs.echo("text") or zs.say("text"), but some Lua people just like to use print instead. Also, the Lua print can handle type-conversion, so you can print the entire contents of a Lua table and stuff like that.
|
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Nov 07, 2007 11:23 am |
Zugg wrote: |
The interface for WSH scripting languages is pretty limited, and they are typically much slower than either zScript, or especially Lua. If you want more efficient scripts, I really can't recommend the WSH languages, and it's hard to share your scripts with others because they might not have ActivePHP installed. |
Given this, is there any chance of implementing / embedding Python into CMUD some time in the future, e.g. CMUD 3.0? *hopeful look with big eyes* There are quite a few programs out there with embedded Python scripting... (For example, SynchronEX, a file synchronizing program that I came across recently.) |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Nov 07, 2007 12:03 pm |
CIV (Civilization IV) also uses Python. Python for Delphi |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Nov 07, 2007 12:53 pm |
The main reason that Lua was included (as opposed to being left for WSH), besides the fact that WSH implementations of Lua suck long and suck hard, is that Lua's lightweight. Python... isn't. All the python binaries and sources I've seen are >10mb, which is more than the size of CMUD (that's not to say that adding Python to CMUD is going to double the installer size, but it's going to add more than Lua's paltry 112k). Adding that much size for something so marginal doesn't seem like the best idea.
And, really, this is what WSH is intended to handle. You don't need to ship 296829682 scripting languages with your program because a user that wants to use some language you've never even heard of just needs to install it in the WSH to get it working. ActivePython works just fine (I've used it) and I'm sure the WSH interface will eventually be improved to have more of the features available to the Lua interface. Adding support for languages individually would be much slower (and bloat CMUD much, much more) than just improving the WSH interface.
I was quite surprised when Zugg agreed to add Lua to CMUD rather than just giving these reasons (I'm sure I've seen threads where adding languages had been talked about in the past and these reasons were given). I guess Lua's size and the (apparent) ease of adding it were the deciding factor. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Nov 07, 2007 5:33 pm |
I wasn't suggesting packaging up and including a complete Python install into CMUD - that would be crazy. I was thinking along the lines of either requiring an existing Python install in the %PATH% (mostly this) or just including python23.dll for the core language features - python23.dll is half the size (952 KB) of python24.dll and python25.dll and there aren't a lot of new language features since 2.3. Maybe a few modules could also be included as the pyc (compiled) files: string, re and maybe os - it would still be under 1 MB. Hmm, I guess that's still too much, so requiring Python to be installed separately isn't a big deal.
I dunno - why is the WSH interface a lot slower? I thought CMUD was bypassing one [of /edit] the Microsoft layers? [The actual WSH layer? /edit] |
|
Last edited by Seb on Wed Nov 07, 2007 6:07 pm; edited 1 time in total |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Nov 07, 2007 5:50 pm |
Thanks for taking my point about the file size in the spirit it was intended - I tried to find a copy of pythonXX.dll (I must have one somewhere) but I'm quite impatient. A meg is on the cusp, I think - certainly it's a bit iffy.
I think the WSH interface is slower simply because it uses COM to communicate with the script host and Lua doesn't, but I haven't read enough on that to be authoritative. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Nov 07, 2007 6:10 pm |
pythonXX.dll is generally in %SystemRoot%\System32.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Nov 07, 2007 6:16 pm |
I doubt I'll ever be directly integrating Python. At some point CMUD could just get overwhelmed with all of the scripting options, and that makes it even harder for people to share their scripts.
The reason Lua was integrated is because it is fast and tiny. By integrating it, people can share Lua scripts because every CMUD user can run it directly. Also, Lua is used in other MUD clients, and other MMOs, so it's a popular language for the gaming community. And, as Fang mentioned, there wasn't any good WSH interface for Lua.
Python is too large to integrate into the CMUD distribution. So you'd always have the problem of sharing scripts with someone that doesn't have Python. And once you get to full-blown languages like Python, where would it end? Perl, PHP, etc are all viable choices, and I'm certainly not going to integrate all of those into CMUD. And all of those languages already *do* have good WSH implementations.
WSH is still the proper choice for adding additional scripting language. Yes, it's a bit slower than Lua just because Lua is using direct DLL calls, whereas WSH is using COM. But COM isn't that much slower, and yes, I am already bypassing one of the Microsoft WSH layers with my own ScriptingHost component.
The main issue right now is that WSH is using the older zMUD API for accessing commands, variables, etc. Lua uses a newer interface that provides more access to CMUD stuff. I still have plans to improve the COM API so that other WSH languages have a similar interface to access CMUD. I just don't know if I'm going to have the time to do this before the 2.0x public release or not. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Nov 07, 2007 8:24 pm |
Fair enough. Perhaps I might learn Lua if I end up doing some new big, complex scripts (or just have a lot of time on my hands). It performs very well on Gentoo : Intel� Pentium� 4 Computer Language Benchmarks Game (3 places above Python). Amusingly, if you change your weighting so that everything is weighted equally, Lua beats Java 6 Server and falls just short of C# on Mono. Someone should translate the tests into zScript and then we can compare zScript with Lua with Python and the other WSH implementations!
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Nov 07, 2007 8:52 pm |
I originally learnt Lua on a whim - I'd intended to ever since I started playing WoW because many of the UI addons are horribly coded (I've reduced the length of some of my addons by as much as 70%!), and they're often broken by patches, but never got round to it. I saw PIL on the Lua site and spent an hour or so at a time going through it until I'd finished. If you have any experience at all (I didn't at the time, beyond zScript) I'm sure you'll be able to blast through it. So yeah, don't feel like it's going to be a mammoth task.
|
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Sat Nov 10, 2007 12:07 am |
That was a series of tutorials on Python for Delphi. I probably should have posted the actual link to it, so in the interests of documentation, and because there is apparently no link to it from there, here it is:
http://mmm-experts.com/Products.aspx?ProductId=3
The site's not especially well designed IMO - the links to the other pages on their site that relate to it are on the left-hand panel. (I missed them the first time I looked at that page.) |
|
|
|
|
|