Skip to content

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

Notifications You must be signed in to change notification settings

matsumotory/mruby-userdata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

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
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

    u = Userdata.new
    u.hoge = {:hoge => 1}
  • The other ruby code B is shared mrb_state with ruby code A

    u = Userdata.new
    hash = u.hoge
    hash[:fuga] = 2
    u.hoge = hash
    
    p u.hoge # => {:hoge => 1, :fuga =>2}
  • use userdata key

    mirb - Embeddable Interactive Ruby Shell
    
    This is a very early version, please test and report errors.
    Thanks :)
    
    > u = Userdata.new
     => #<Userdata:0x7f96ca808ad0 mrb_userdata_key_store="mrb_userdata_default_key">
    > u.hoge
     => nil
    > u.hoge = 1
     => 1
    > u.hoge
     => 1
    > q = Userdata.new
     => #<Userdata:0x7f96ca808590 mrb_userdata_key_store="mrb_userdata_default_key">
    > q.hoge
     => 1
    > q.hoge = q.hoge + 1
     => 2
    > u.hoge
     => 2
    > s = Userdata.new "my_key"
     => #<Userdata:0x7f96ca807d80 mrb_userdata_key_store="my_key">
    > s.hoge
     => nil
    > s.hoge = 1
     => 1
    > u.hoge
     => 2
    > q.hoge
     => 2

License

under the MIT License:

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •