Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a CLI with mruby-cli

E822acb0564c5632aae69fef35f85b3d?s=47 Scalone
September 12, 2016

Building a CLI with mruby-cli

Talk about mruby-cli at the 41st GURU-SP meeting

E822acb0564c5632aae69fef35f85b3d?s=128

Scalone

September 12, 2016
Tweet

Transcript

  1. THIAGO SCALONE - @scalone CLI WITH MRUBY-CLI

  2. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  3. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  4. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  5. WHY?

  6. Web API Mail

  7. Web API Mail Analytics

  8. Web API Mail Analytics Communication

  9. Web API Mail Analytics Communication Monitoring

  10. Web API Mail Analytics Communication Monitoring Authentication

  11. Web API Mail Analytics Communication Monitoring Authentication Errors

  12. $ my-cli

  13. NO BROWSER

  14. Who Github - Hub Heroku - Heroku Toolbelt AWS -

    aws-cli Trello - trelo_cli Slack - slack-cli CW - cloudwalk
  15. None
  16. None
  17. gem install heroku

  18. CRuby Requires Ruby

  19. CRuby Requires Ruby Performance (Require)

  20. CRuby Requires Ruby Performance (Require) Ruby Versions

  21. CRuby Requires Ruby Performance (Require) Ruby Versions Packaging Problems

  22. :(

  23. None
  24. $ GOOS=linux GOARCH=amd64 go build $ GOOS=windos GOARCH=amd64 go build

    $ GOOS=darwin GOARCH=amd64 go build
  25. None
  26. None
  27. None
  28. HAPPY! I feel

  29. None
  30. mruby-cli

  31. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  32. mruby-cli Ruby Performance No Require Binary for each platform Simple

    compile and release CLI apps framework
  33. WHY?

  34. mruby

  35. None
  36. MRuby ISO/IEC 30170:2012

  37. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 / 2.1 Syntax

  38. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 / 2.1 Syntax No built-in

    IO/Thread/stdlib
  39. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 / 2.1 Syntax No built-in

    IO/Thread/stdlib Cross-compilation / ANSI C
  40. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 / 2.1 Syntax No built-in

    IO/Thread/stdlib Cross-compilation / ANSI C No gems, but mrbgems
  41. runtime Operation System

  42. runtime Operation System SDK / Dynlib

  43. runtime Operation System SDK / Dynlib MRuby VM

  44. runtime Operation System SDK / Dynlib MRuby VM Mrbgem

  45. runtime Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  46. runtime Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  47. static Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  48. mrbgem Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  49. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  50. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  51. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  52. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  53. runtime Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  54. $ echo "puts 'Hello GURU-SP'" >> guru.rb $ mrbc guru.rb

    $ hexdump -C guru.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......Hello GUR| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |U-SP......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b guru.mrb Hello GURU-SP
  55. $ echo "puts 'Hello GURU-SP'" >> guru.rb $ mrbc guru.rb

    $ hexdump -C guru.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......Hello GUR| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |U-SP......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b guru.mrb Hello GURU-SP
  56. $ echo "puts 'Hello GURU-SP'" >> guru.rb $ mrbc guru.rb

    $ hexdump -C guru.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......Hello GUR| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |U-SP......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b guru.mrb Hello GURU-SP
  57. $ echo "puts 'Hello GURU-SP'" >> guru.rb $ mrbc guru.rb

    $ hexdump -C guru.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......Hello GUR| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |U-SP......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b guru.mrb Hello GURU-SP
  58. guru[] = { 0x45,0x54,0x49,0x52,0x30,0x30,0x30,0x33,0x78,0xfb,0x00,0x00,0x00,0x67,0x4d,0x41, 0x54,0x5a,0x30,0x30,0x30,0x30,0x49,0x52,0x45,0x50,0x00,0x00,0x00,0x49,0x30,0x30, 0x30,0x30,0x00,0x00,0x00,0x41,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04, 0x06,0x00,0x80,0x00,0x3d,0x00,0x00,0x01,0xa0,0x00,0x80,0x00,0x4a,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0x00,0x00,0x0d,0x48,0x65,0x6c,0x6c,0x6f,0x20,0x47,0x55,0x52, 0x55,0x2d,0x53,0x50,0x00,0x00,0x00,0x01,0x00,0x04,0x70,0x75,0x74,0x73,0x00,0x45, 0x4e,0x44,0x00,0x00,0x00,0x00,0x08,

    };
  59. int main(void) { mrb_state *mrb = mrb_open(); mrbc_context *c; mrb_value

    v; c = mrbc_context_new(mrb); mrb_load_irep_cxt(mrb, guru, c); mrbc_context_free(mrb, c); return 0; }
  60. int main(void) { mrb_state *mrb = mrb_open(); mrbc_context *c; mrb_value

    v; c = mrbc_context_new(mrb); mrb_load_irep_cxt(mrb, guru, c); mrbc_context_free(mrb, c); return 0; }
  61. $ gcc -o guru guru.c -I mruby/include mruby/build/host/lib/libmruby.a $ ./guru

    Hello GURU-SP
  62. $ gcc -o guru guru.c -I mruby/include mruby/build/host/lib/libmruby.a $ ./guru

    Hello GURU-SP
  63. .RB Review

  64. BYTECODE MRB .RB Review

  65. BYTECODE MRB VM + MRBGEM + MRB .RB Review

  66. BYTECODE MRB VM + MRBGEM + MRB BIN .RB Review

  67. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  68. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  69. + = https://github.com/hone mrub

  70. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  71. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  72. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  73. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  74. None
  75. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  76. DEMO https:/ /github.com/scalone/guru41

  77. TIPS

  78. None
  79. number of malloc calls: 6480 number of realloc calls: 0

    number of free calls: 1436 number of free(!NULL) calls: 334 number of free(NULL) calls: 1102 total size of allocated memory: 689710 bytes current number of allocated objects: 6146 current size of allocated memory: 611230 bytes mruby-memprof
  80. Windows

  81. Windows

  82. Windows

  83. Windows

  84. DAFUNK, OPEN SOURCE RUBY FRAMEWORK FOR IOT @scalone

  85. We're hiring thiago@cloudwalk.io

  86. Thank you @scalone THIAGO SCALONE - thiago@scalone.com.br