Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA authored Oct 13, 2024
1 parent 4df03cc commit 3fb4c3d
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,40 @@ if state[:flag_1]
end
```

Ruby is good at creating DSLs.
For example, you can easily write `cmd` to your liking by adding method and class definitions.

```ruby
# When the method is defined...
def move(id, to) = cmd :move, id:, to:

# It can be written like this
move "Bob", [5, 5]
```
```ruby
# Making full use of class definitions and instance_eval...
class CharacterContext
def initialize(id)
@id = id
end

def move(to)
cmd :move, id: @id, to: to
end
end

def with(id, &block)
CharacterContext.new(id).instance_eval(block)
end

# It can be written like this.
with(:Bob) do
move [5, 5]
end
```


Each time the `cmd` call is made, VitalRouter publishes an `ICommand`.
The way to subscribe to this is the same as in the usual VitalRouter.

Expand Down Expand Up @@ -1177,39 +1211,6 @@ await script.RunAsync();
script.Dispose();
```

Ruby is good at creating DSLs.
For example, you can easily write `cmd` to your liking by adding method and class definitions via `MRubyContext.Load`.

```ruby
# When the method is defined...
def move(id, to) = cmd :move, id:, to:

# It can be written like this
move "Bob", [5, 5]
```
```ruby
# Making full use of class definitions and instance_eval...
class CharacterContext
def initialize(id)
@id = id
end

def move(to)
cmd :move, id: @id, to: to
end
end

def with(id, &block)
CharacterContext.new(id).instance_eval(block)
end

# It can be written like this.
with(:Bob) do
move [5, 5]
end
```

By default, syntax errors and runtime errors that occur in mruby scripts are reported via `UnityEngine.Debug.LogError`.
To customize this, do the following:

Expand Down

0 comments on commit 3fb4c3d

Please sign in to comment.