Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/matsumotory/mruby-userdata

When shared mrb_state, you can share userdata objects between one Ruby code and another is shared mrb_state.
https://github.com/matsumotory/mruby-userdata

Last synced: 2 months ago
JSON representation

When shared mrb_state, you can share userdata objects between one Ruby code and another is shared mrb_state.

Awesome Lists containing this project

README

        

# Userdata class for mruby
When shared mrb_state, you can share userdata objects between one Ruby code and the other.

## install by mrbgems
- add conf.gem line to `build_config.rb`
```ruby
MRuby::Build.new do |conf|

# ... (snip) ...

conf.gem :git => 'https://github.com/matsumoto-r/mruby-userdata.git'
end
```

## How to use
- One ruby code A

```ruby
u = Userdata.new
u.hoge = {:hoge => 1}
```

- The other ruby code B is shared mrb_state with ruby code A

```ruby
u = Userdata.new
hash = u.hoge
hash[:fuga] = 2
u.hoge = hash

p u.hoge # => {:hoge => 1, :fuga =>2}
```

- use userdata key

```ruby
mirb - Embeddable Interactive Ruby Shell

This is a very early version, please test and report errors.
Thanks :)

> u = Userdata.new
=> #
> u.hoge
=> nil
> u.hoge = 1
=> 1
> u.hoge
=> 1
> q = Userdata.new
=> #
> q.hoge
=> 1
> q.hoge = q.hoge + 1
=> 2
> u.hoge
=> 2
> s = Userdata.new "my_key"
=> #
> s.hoge
=> nil
> s.hoge = 1
=> 1
> u.hoge
=> 2
> q.hoge
=> 2
```

# License
under the MIT License:

* http://www.opensource.org/licenses/mit-license.php