![]() |
#1 |
New Member
Join Date: Nov 2003
Posts: 7
![]() |
|
![]() |
![]() |
![]() |
#2 |
New Member
Join Date: Jul 2002
Location: Canada
Posts: 17
![]() |
<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. |
![]() |
![]() |
![]() |
#3 |
Senior Member
|
![]() 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. |
![]() |
![]() |
![]() |
#4 |
Senior Member
|
![]() 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. |
![]() |
![]() |
![]() |
#5 |
New Member
Join Date: Jul 2002
Location: Canada
Posts: 17
![]() |
|
![]() |
![]() |
![]() |
#6 |
New Member
Join Date: Nov 2003
Posts: 7
![]() |
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.). |
![]() |
![]() |
![]() |
#7 |
New Member
Join Date: Jul 2002
Location: Canada
Posts: 17
![]() |
|
![]() |
![]() |
![]() |
#8 |
Senior Member
|
![]() 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' =).
|
![]() |
![]() |
![]() |
#9 |
New Member
Join Date: Nov 2003
Posts: 7
![]() |
|
![]() |
![]() |
![]() |
#10 |
New Member
Join Date: Nov 2003
Posts: 7
![]() |
|
![]() |
![]() |
![]() |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
What language? | Aeran | MUD Coding | 9 | 04-27-2007 04:11 PM |
Scripting | gutterzombie | MUD Builders and Areas | 6 | 01-28-2004 01:30 PM |
Internal Scripting Languages | xanes | Advanced MUD Concepts | 10 | 05-19-2003 05:12 PM |
Embedding scripting languages | Artovil | Advanced MUD Concepts | 6 | 09-13-2002 02:01 AM |
shell scripting | Emit | MUD Coding | 3 | 05-26-2002 02:48 PM |
|
|