Phantasmal MUD Lib for DGD
Phantasmal Site > Phantasmal Tutorials > Administration > Evaluating Arbitrary Code Evaluating Arbitrary CodeWhen you were compiling code earlier, you may have thought it was a little odd to see a result like "$0 = </usr/System/initd>". This tutorial will tell you what that means. The %history command will show you values like $0 above if you type it by itself from the command line. You should see all the results that you got from the %compile, %clone and %code commands. Clone? Code? Those are new ones. Let's hit %clone first. You'll need to pick a clonable object, one that could be useful to clone, or at least not going to cause an error. So daemons like InitD are right out. Instead, try typing "%clone /usr/common/obj/simple_portable". It should return something like "$2 = </usr/common/obj/simple_portable>". But you don't want something like that hanging around without supervision, so go ahead and get rid of it. Type "%destruct $2" -- but use whatever number you got back from %clone, don't just destruct history object number 2. Note that if instead we had typed "%destruct /usr/common/obj/simple_portable", it would not have done the same thing -- there are specific, individual clones of each cloneable object, and they take some tracking down. You can see how many a given object has by typing "%od_report <object>", though there are some subtleties there -- it may not report the full number if you have multiple issues of an object that aren't properly upgraded. If this is all greek to you, don't worry about it. Just take my word for it that specific individual clones are tough to track down, so make sure to destruct the ones you create. Now that you've carefully cleaned up after yourself, go ahead and type "%clear". It'll clear out your entire history list so far and you'll lose any references to things that you were keeping around. That's why you cleaned up first. And that leaves only the %code command to introduce. Go ahead and type "%code 4". You'll get a result like "$17 = 4". Exciting, huh? But you can use the same thing to evaluate arbitrary LPC code, and that's much more interesting. For instance, you could type "%code ({ 1, 7, 9 }) [1]", which should return the value 7. Or you can cause side-effects by calling objects in Phantasmal. A pretty harmless example is "%code find_object("/usr/common/sys/mapd")->get_room_by_num(7)" which should find the MAPD and return you a reference to object #7, or nil. Naturally you can also reduce it to "%code find_object("/usr/common/sys/mapd")" and then use the number it returns -- for instance, if it came back with "$34 = </usr/common/sys/mapd>", you could then say "%code $34->get_room_by_num(347)". So there are your fun toys of the day. Knock yourself out. And keep reading tutorials! |