Shadowfirebird
7/31/2008 8:53:00 PM
Sorry: I should have said, "Hi Tim".
On Thu, Jul 31, 2008 at 9:48 PM, Shadowfirebird
<shadowfirebird@gmail.com> wrote:
> Hi Robert,
>
> It seems to me that that's a hell of a difficult thing to do.
>
> Take your Sword.new() call. There are a lot of different ways I
> might code that (especially in Ruby!). A simple search and replace
> will probably not be very reliable.
>
> s = Sword.new()
> OR
> swords = []; swords << sword.new()
> OR
> Event.new(Sword.new.strike(:martin))
>
> ...or whatever. And that's just one statement -- it says nothing of
> the multitude of different ways that a given problem can be solved
> using Ruby code.
>
> Is there any particular reason why you need to translate Ruby to LPC?
> Why not just use Ruby as the in-game language?
>
>
> (Confession time: I'm writing a MUSH myself, although mine is really
> just a learning exercise, and, I suspect, a great deal less ambitious
> than your project. For various reasons I'd dismissed the idea of
> users writing code within the game, one of them being that I couldn't
> see of any easy way to protect the game from malicious code. I'd be
> interested on your thoughts on this, either inside or outside the
> list.)
>
> Shadowfirebird.
>
>
> On Thu, Jul 31, 2008 at 7:49 PM, Robert Klemme
> <shortcutter@googlemail.com> wrote:
>> On 31.07.2008 20:22, Tim Mcd wrote:
>>>
>>> So, I am currently working on a MUD (Online multiplayer text based game,
>>> like an MMO). The MUD's scripting language is LPC. I am trying to create
>>> a ruby script, that reads another ruby file, and changes all instances
>>> of 'Sword-of-might = Sword.new(...)' to something like 'static void
>>> create() {...}'. Nothing too fancy, just me being able to go through a
>>> file finding different bits of ruby that I can then replace with the
>>> equivalent LPC code.
>>>
>>> An example of how it might work is: Ruby has a table of ruby phrases and
>>> what to turn them into if encountered. Ruby then reads the given file,
>>> and if it finds any of the given phrases, turns them into the
>>> corresponding LPC that I have defined.
>>>
>>> So, the problem is, I have no idea how to go about doing something
>>> like this in Ruby. Any thoughts/help or places to look? (tutorials,
>>> etc.)
>>
>> Depends how many phrases you got there. If there are just a few of them and
>> they are fixed, you can do something like this:
>>
>> phrases = {
>> "foo" => "bar",
>> "baz" => "boo!",
>> }
>>
>> dat = File.read input_file
>>
>> dat.gsub! Regexp.union(phrases.keys) do |m|
>> phrases[m] or raise "Phrase not found: #{m.inspect}"
>> end
>>
>> File.open out, "w" do |io|
>> io.write dat
>> end
>>
>> Kind regards
>>
>> robert
>>
>>
>
>
>
> --
> Me, I imagine places that I have never seen / The colored lights in
> fountains, blue and green / And I imagine places that I will never go
> / Behind these clouds that hang here dark and low
> But it's there when I'm holding you / There when I'm sleeping too /
> There when there's nothing left of me / Hanging out behind the
> burned-out factories / Out of reach but leading me / Into the
> beautiful sea
>
>
--
Me, I imagine places that I have never seen / The colored lights in
fountains, blue and green / And I imagine places that I will never go
/ Behind these clouds that hang here dark and low
But it's there when I'm holding you / There when I'm sleeping too /
There when there's nothing left of me / Hanging out behind the
burned-out factories / Out of reach but leading me / Into the
beautiful sea