Top Mud Sites Forum

Top Mud Sites Forum (http://www.topmudsites.com/forums/index.php)
-   MUD Coding (http://www.topmudsites.com/forums/forumdisplay.php?f=9)
-   -   Which scripting language? (http://www.topmudsites.com/forums/showthread.php?t=383)

Gakusei 03-13-2004 09:31 AM


Blobule 03-13-2004 11:26 AM

<shamelessPlug>
You mean something like this:



</shamelessPlug>

I'd say the joy was in writing it. And it's completely sandboxed and under
my control. Before I wrote it I considered embedding PHP but then I figured
that would be more of a hassle, and also I wanted my legacy easyact
scripts to be compatible... so I started from scratch. In retrospect now
that I've done it, there are things I can do I don't think would have been
easy to do with PHP since I can fully control a running context from
within a function (kill it, pause it, jump to an arbitrary code segment). As it
stands though, it sucks my time like a black hole.

Yui Unifex 03-13-2004 11:33 AM

My public domain codebase, Aetas, has embedded Ruby for scripting. It performs admirably for every purpose you list.

Embedding Ruby is not too hard. I'll respond to your requirements in turn with how I implemented it in Ruby.
This is more a function of your codebase than the language you are embedding. My objects keep a list of 'Triggers' that fire upon some event being emitted. The trigger simply contains the text of a Ruby script.

This, also, is more a function of your codebase then the language you use. I use a property list for pretty much all accessible values, e.g., player->get("name") will return the string name of the player, and player->set("hp", "10") will set their hitpoints to 10. It's very easy to wrap these properties in whatever scripting language you choose. I simply provide a 'rubyval' function that converts the value into a Ruby VALUE by using rb_str_new for strings, or INT2FIX for numbers.

I do not have variables that are global to the world; but if I did, I would be using the same system of properties. I'd merely implement them on the global 'Game' class instead of a specific object.

Every object that I use for scripting has a Ruby class defined for it. You can use Data_Wrap_Struct to wrap a pointer into a Ruby class so that 'self' refers to it. In this way you write your Ruby pretty much the same way that you write your C++. For example:
[code] class Element
...
def cmdSay (args)
return if args.empty?

msg = "<#{name}> #{args}\n"
room.broadcast(msg)
room.sendevent(EVENT_TEXT, self, args, args)
end
...[/quote]
Since the 'say' command executes within the context of 'Element' (my toplevel entity), the 'room' in this method refers to the room in which the Element resides. So it functions rather naturally.

Although this sorta feels like an advertisement, implements exactly what you're asking, so feel free to check it out and post any questions you might have.

Yui Unifex 03-13-2004 11:46 AM

I was just chastised for leaving out an essential part of our say command. Behold the power of Ruby!
[code] class Element
def dumbass (msg, &code)
if get("dumbass") then
send(msg)
dumbasses = get("dumbass").to_s
dumbasses.split(",").each { |dname|
person = Game.find_player dname
person.send(msg) if person
}
else
yield
end
end

def cmdSay (args)
return if args.empty?

msg = "<#{name}> #{args}\n"
dumbass(msg) {
room.broadcast(msg)
room.sendevent(EVENT_TEXT, self, args, args)
}
end[/quote]
Had some players getting too annoying, so we implemented a property for making messages they send only send to themselves or their little friends =). All without a reboot, btw.

Blobule 03-13-2004 12:06 PM


Gakusei 03-13-2004 01:19 PM

Thankyou very much! I took a quick look and both of those systems look like they could be extremely helpful. I'll take a closer look over the course of the next week or so.

Here's another poser, related to my first question:

Another approach I am considering is writing the server entirely in an interpreted language like perl or ruby. I was wondering if anyone knows if it is possible to create an instance of a class which has basic functionality, then loading a script into that particular instance. What would be even more helpful is if it would override existing methods.

In more detail:

-> A class 'room' is defined.
-> The class definition contains a method 'DropItem' which defines the default behaviour for dropping an item into that room.
-> An instance of a room is created.
-> A script is loaded into this instance that redefines 'DropItem' for this room and this room only.

I don't know if this is possible, but I had a look through some documentation and perl's 'eval' looks interesting. I should note that I am not concerned about security at this point.

This approach interests me for a few reasons: Less work, regular expressions (which I presume would come in handy in a text enviroment) and learning a new language (I am not familiar with perl/ruby/etc.).

Blobule 03-13-2004 01:50 PM


Yui Unifex 03-13-2004 04:22 PM

Any scripting language can do this easily. If you were writing a server entirely in the scripting language, then a better idea would be to use polymorphism to provide your overriding. We call this 'subclassing' =).

Gakusei 03-13-2004 05:04 PM


Gakusei 03-14-2004 08:39 AM



All times are GMT -4. The time now is 03:34 AM.

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Top Mud Sites.com 2022