<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Junichi Kajiwara</title>
    <description>The latest articles on Forem by Junichi Kajiwara (@kjunichi).</description>
    <link>https://forem.com/kjunichi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F41878%2F5c75b780-fd66-4604-b769-82694ef8ad99.jpeg</url>
      <title>Forem: Junichi Kajiwara</title>
      <link>https://forem.com/kjunichi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kjunichi"/>
    <language>en</language>
    <item>
      <title>Multi dimensional array in rust</title>
      <dc:creator>Junichi Kajiwara</dc:creator>
      <pubDate>Thu, 19 Jul 2018 09:39:59 +0000</pubDate>
      <link>https://forem.com/kjunichi/multi-dimensional-array-in-rust-3iib</link>
      <guid>https://forem.com/kjunichi/multi-dimensional-array-in-rust-3iib</guid>
      <description>&lt;div class="instagram-position"&gt;
  &lt;iframe id="instagram-liquid-tag" src="https://www.instagram.com/p/BlRWpqansFh/embed/captioned"&gt;
  &lt;/iframe&gt;
  
&lt;/div&gt;


</description>
      <category>rust</category>
    </item>
    <item>
      <title>How to build plv8 2.3.0 for Raspberry Pi 3</title>
      <dc:creator>Junichi Kajiwara</dc:creator>
      <pubDate>Thu, 22 Mar 2018 11:04:16 +0000</pubDate>
      <link>https://forem.com/kjunichi/how-to-build-plv8-230-for-raspberry-pi3-2n09</link>
      <guid>https://forem.com/kjunichi/how-to-build-plv8-230-for-raspberry-pi3-2n09</guid>
      <description>&lt;h1&gt;
  
  
  What is plv8
&lt;/h1&gt;

&lt;p&gt;see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pgxn.org/dist/plv8/doc/plv8.html"&gt;https://pgxn.org/dist/plv8/doc/plv8.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Building V8
&lt;/h1&gt;

&lt;p&gt;I have done this by cross compiling.&lt;/p&gt;

&lt;p&gt;You have to do following steps on Linux box(x86_64).&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing depot_tools
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nb"&gt;local&lt;/span&gt;/src
&lt;span class="nb"&gt;cd local
mkdir &lt;/span&gt;build
&lt;span class="nb"&gt;cd &lt;/span&gt;build
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;:~/local/depot_tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  fetching v8 source
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;src
fetch v8
&lt;span class="nb"&gt;cd &lt;/span&gt;v8
git checkout 6.4.388.40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6.4.388.40 : plv8-2.3.0 uses this version.&lt;/p&gt;

&lt;p&gt;You may add follwing line to ../.gclient .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;target_os = ['unix']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then, you call gclient sync.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gclient &lt;span class="nb"&gt;sync&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cross compileing for Raspberry Pi
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tools/dev/v8gen.py arm.release &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nv"&gt;is_component_build&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false &lt;/span&gt;&lt;span class="nv"&gt;v8_static_library&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;&lt;span class="nv"&gt;v8_use_snapshot&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="se"&gt;\ &lt;/span&gt;
&lt;span class="nv"&gt;v8_use_external_startup_data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false &lt;/span&gt;&lt;span class="nv"&gt;v8_enable_i18n_support&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gn args out.gn/arm.release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then,edit parameters following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;is_debug = false
target_cpu = "arm"
v8_target_cpu = "arm"

# Additional command-line args:
is_component_build=false
v8_static_library=true
v8_use_snapshot=true
v8_use_external_startup_data=false
v8_enable_i18n_support=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  building d8 and libv8*.a
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ninja &lt;span class="nt"&gt;-C&lt;/span&gt; out.gn/arm.release d8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When your build success,you'll have these files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls &lt;/span&gt;out.gn/arm.release/libv8&lt;span class="k"&gt;*&lt;/span&gt;.a
libv8_base.a
libv8_libbase.a
libv8_libplatform.a
libv8_libsampler.a
libv8_snapshot.a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Copying files to raspberry pi
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh pi@raspberrry.local &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/local/v8
scp out.gn/arm.release/libv8&lt;span class="k"&gt;*&lt;/span&gt;.a pi@raspberrypi.local:/home/pi/local/v8
scp include pi@raspberrypi.local:/home/pi/local/v8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after this step,you may work on your raspberry pi.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installing libc++
&lt;/h1&gt;

&lt;p&gt;before build plv8,you'll need libc++.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;libc++-dev libunwind-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Installing PostgreSQL
&lt;/h1&gt;

&lt;p&gt;Of course you'll need PostgreSQL.Because plv8 is an extension of the PostgreSQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;postgresql-server-dev-9.6 postgresql-9.6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Building plv8 itself on Raspberry Pi
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/local/src
&lt;span class="nb"&gt;cd&lt;/span&gt; ~/local/src
curl https://github.com/plv8/plv8/archive/v2.3.0.zip
unzip v2.3.0.zip
&lt;span class="nb"&gt;cd &lt;/span&gt;plv8-2.3.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  copy v8 headers and libraries to plv8's source tree
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p build/v8/out.gn/x64.release/obj
cp -r ~/local/v8/include build/v8
cp ~/local/v8/lib*a build/v8/out.gn/x64.release/obj
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Edit Makefile
&lt;/h2&gt;

&lt;p&gt;Now, you have built v8 libraries.you don't need build v8 again.&lt;br&gt;
So, you can edit Makefile following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;AUTOV8_DIR = build/v8
AUTOV8_OUT = build/v8/out.gn/x64.release/obj
&lt;/span&gt;&lt;span class="gd"&gt;- AUTOV8_DEPOT_TOOLS = build/depot_tools
&lt;/span&gt;&lt;span class="p"&gt;AUTOV8_LIB = $(AUTOV8_OUT)/libv8_snapshot.a
AUTOV8_STATIC_LIBS = -lv8_base -lv8_snapshot -lv8_libplatform -lv8_libbase -lv8_libsampler
&lt;/span&gt;&lt;span class="gd"&gt;- export PATH := $(abspath $(AUTOV8_DEPOT_TOOLS)):$(PATH)
&lt;/span&gt;
SHLIB_LINK += -L$(AUTOV8_OUT) -L$(AUTOV8_OUT)/third_party/icu $(AUTOV8_STATIC_LIBS)
&lt;span class="gd"&gt;-- V8_OPTIONS = is_component_build=false v8_static_library=true v8_use_snapshot=true v8_use_external_startup_data=false
&lt;/span&gt;
- ifndef USE_ICU
&lt;span class="gd"&gt;-   V8_OPTIONS += v8_enable_i18n_support=false
- endif
&lt;/span&gt;
- all: v8

# For some reason, this solves parallel make dependency.
&lt;span class="gd"&gt;- plv8_config.h plv8.so: v8
&lt;/span&gt;
- $(AUTOV8_DEPOT_TOOLS):
&lt;span class="gd"&gt;-   mkdir -p build
-   cd build; git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
&lt;/span&gt;
- $(AUTOV8_DIR): $(AUTOV8_DEPOT_TOOLS)
&lt;span class="gd"&gt;-   cd build; fetch v8; cd v8; git checkout $(AUTOV8_VERSION); gclient sync ; tools/dev/v8gen.py x64.release -- $(V8_OPTIONS)
&lt;/span&gt;
- $(AUTOV8_OUT)/third_party/icu/common/icudtb.dat:

- $(AUTOV8_OUT)/third_party/icu/common/icudtl.dat:

- v8: $(AUTOV8_DIR)
&lt;span class="gd"&gt;-   cd $(AUTOV8_DIR) ; env CXXFLAGS=-fPIC CFLAGS=-fPIC ninja -C out.gn/x64.release d8
&lt;/span&gt;
include Makefile.shared

CCFLAGS += -I$(AUTOV8_DIR)/include -I$(AUTOV8_DIR)
&lt;span class="err"&gt;#&lt;/span&gt; We're gonna build static link.  Rip it out after include Makefile
&lt;span class="p"&gt;SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK))
&lt;/span&gt;
ifeq ($(OS),Windows_NT)
    # noop for now
&lt;span class="p"&gt;else
&lt;/span&gt;    SHLIB_LINK += -L$(AUTOV8_OUT)
    UNAME_S := $(shell uname -s)
    ifeq ($(UNAME_S),Darwin)
        CCFLAGS += -stdlib=libc++ -std=c++11
        SHLIB_LINK += -stdlib=libc++
    endif
    ifeq ($(UNAME_S),Linux)
        CCFLAGS += -std=c++11
&lt;span class="gd"&gt;-       SHLIB_LINK += -lrt -std=c++11 -lc++
&lt;/span&gt;&lt;span class="gi"&gt;+       SHLIB_LINK += -lrt -std=c++11 -lc++ -lunwind
&lt;/span&gt;    endif
&lt;span class="p"&gt;endif
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Building plv8
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing postgres extension
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;make &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  run
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;su - postgres
psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE EXTENSION plv8;
SELECT plv8_version();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>raspberrypi</category>
      <category>postgres</category>
      <category>javascript</category>
      <category>v8</category>
    </item>
    <item>
      <title>Reading the message written in binary for Ruby 25th Anniversary using by mruby.</title>
      <dc:creator>Junichi Kajiwara</dc:creator>
      <pubDate>Thu, 22 Feb 2018 05:20:07 +0000</pubDate>
      <link>https://forem.com/kjunichi/reading-the-message-written-in-binary-for-ruby-25th-anniversary-using-by-mruby--4imi</link>
      <guid>https://forem.com/kjunichi/reading-the-message-written-in-binary-for-ruby-25th-anniversary-using-by-mruby--4imi</guid>
      <description>&lt;p&gt;Hello,I found this tweet.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-966421801705267200-549" src="https://platform.twitter.com/embed/Tweet.html?id=966421801705267200"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-966421801705267200-549');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=966421801705267200&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;I wonder what is written and I tried to read using by mruby.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;It seemed that the binary code is ascii code.&lt;/p&gt;

&lt;p&gt;I wrote the decode binary code in mruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;rawData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"01001001 00100000 01001100 01101111 01110110 01100101 00100000 01010010 01110101 01100010 01111001 00101110"&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;rawData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)}.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"UTF-8"&lt;/span&gt;&lt;span class="p"&gt;)}.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bin/mirb 
mirb - Embeddable Interactive Ruby Shell

&amp;gt; rawData = "01001001 00100000 01001100 01101111 01110110 01100101 00100000 01010010 01110101 01100010 01111001 00101110"
 =&amp;gt; "01001001 00100000 01001100 01101111 01110110 01100101 00100000 01010010 01110101 01100010 01111001 00101110"
&amp;gt; puts rawData.split(" ").map{|c| c.to_i(2)}.map{|c| c.chr("UTF-8")}.join
I Love Ruby.
 =&amp;gt; nil
&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I noticed that Ruby has putc, but mruby didn't have.&lt;/p&gt;

&lt;h2&gt;
  
  
  epilogue
&lt;/h2&gt;

&lt;p&gt;to tell the truth,I first time I wrote decode code in JavaScript.&lt;br&gt;
but I thought this is a chanse to learn mruby,so I wrote this in mruby.&lt;/p&gt;

&lt;h1&gt;
  
  
  Link
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/mruby/mruby" rel="noopener noreferrer"&gt;https://github.com/mruby/mruby&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>mruby</category>
    </item>
    <item>
      <title>require('./opencv.js') is not enough for using OpenCV.js</title>
      <dc:creator>Junichi Kajiwara</dc:creator>
      <pubDate>Tue, 28 Nov 2017 03:27:08 +0000</pubDate>
      <link>https://forem.com/kjunichi/requireopencvjs-is-not-enough-for-using-opencvjs-8ff</link>
      <guid>https://forem.com/kjunichi/requireopencvjs-is-not-enough-for-using-opencvjs-8ff</guid>
      <description>&lt;h1&gt;
  
  
  Begin
&lt;/h1&gt;

&lt;p&gt;I noticed that I can use official OpenCV with JavaScript(WASM).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.opencv.org/3.3.1/d4/da1/tutorial_js_setup.html"&gt;https://docs.opencv.org/3.3.1/d4/da1/tutorial_js_setup.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  The problem
&lt;/h1&gt;

&lt;p&gt;When I wrote code following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./opencv.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;cv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Mat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately I've got only error messages like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeError: cv.Mat is not a constructor
    at Object.&amp;lt;anonymous&amp;gt; (/Volumes/EXTHDD3/local/opencv/build_wasm/bin/dame.js:3:11)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Function.Module.runMain (module.js:682:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:613:3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Solution 1
&lt;/h1&gt;

&lt;p&gt;I think I need some wait, and I rewrite the code following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./opencv.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;cv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Mat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
                &lt;span class="nx"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time,there is no error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ width: 0, height: 0 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Solution 2
&lt;/h1&gt;

&lt;p&gt;Solution 1 is not goot at looking, and depends on CPU's speed.&lt;/p&gt;

&lt;p&gt;I found that Emscipten will call onRuntimeInitialized when it's ready to call main function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./opencv.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;cv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;onRuntimeInitialized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;cv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Mat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
          &lt;span class="nx"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ width: 0, height: 0 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>emscripten</category>
      <category>opencv</category>
      <category>node</category>
    </item>
    <item>
      <title>Called the library created by Go from mruby on Windows and displayed the image of the web camera at the command prompt</title>
      <dc:creator>Junichi Kajiwara</dc:creator>
      <pubDate>Thu, 16 Nov 2017 01:32:41 +0000</pubDate>
      <link>https://forem.com/kjunichi/called-the-library-created-by-go-from-mruby-on-windows-and-displayed-the-image-of-the-web-camera-at-the-command-prompt-chb</link>
      <guid>https://forem.com/kjunichi/called-the-library-created-by-go-from-mruby-on-windows-and-displayed-the-image-of-the-web-camera-at-the-command-prompt-chb</guid>
      <description>&lt;h1&gt;
  
  
  background
&lt;/h1&gt;

&lt;p&gt;I created a library in Go language specifying files and URLs at the Windows command prompt and displaying images at the command prompt&lt;/p&gt;

&lt;h1&gt;
  
  
  Preparation
&lt;/h1&gt;

&lt;p&gt;The Go side inputs jpeg and png as the input source, as it is, it will call from mruby via the file as it is, worrying about the burden on the SSD w. Of course speed too.&lt;/p&gt;

&lt;h2&gt;
  
  
  To treat the start address passed from C as a slice of Go
&lt;/h2&gt;

&lt;p&gt;I found this link:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/golang/go/issues/13656"&gt;https://github.com/golang/go/issues/13656&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apparently,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/golang/go/wiki/cgo#Turning_C_arrays_into_Go_slices"&gt;https://github.com/golang/go/wiki/cgo#Turning_C_arrays_into_Go_slices&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It seems to be nice to write (there seems to be a limitation on the capacity up to 2 GB ..)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;termPutImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;imageData&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uchar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;len&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;
    &lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uchar&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="n"&gt;unsafe&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Pointer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;imageData&lt;/span&gt;&lt;span class="p"&gt;))[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  To convert to the Image type of Go language
&lt;/h2&gt;

&lt;p&gt;As shown below, we were able to convert the array (P6 format of PPM) received from C side to Image type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;img&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewRGBA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Rect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="kt"&gt;uint8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)])&lt;/span&gt;
        &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="kt"&gt;uint8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="kt"&gt;uint8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RGBA&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SetRGBA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  To make libhogehoge.a format as Go
&lt;/h2&gt;

&lt;p&gt;On Windows, shared libraries can not be created, but output of archive format libraries is supported.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go build &lt;span class="nt"&gt;-buildmode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; c-archive &lt;span class="nt"&gt;-o&lt;/span&gt; libimgtype.a main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a library in .a format. For MinGW's gcc environment, you can use it immediately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make MSVC mruby available create a lib file and link
&lt;/h2&gt;

&lt;p&gt;The mrbgem named &lt;a href="https://github.com/kjunichi/mruby-webcam"&gt;mruby-webcam&lt;/a&gt; we are about to use this time uses the MSVC version of OpenCV, and according to it, we will use MSVC.&lt;/p&gt;

&lt;p&gt;Therefore, prepare a def file and generate a. Dll format from this and the .a(archive) format library of the previous. Also, generate the necessary .lib file from .def when linking in MSVC processing system. It will be necessary to do some troublesome work.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to make a dll
&lt;/h1&gt;

&lt;p&gt;The DLL went with the MinGW version of gcc (gcc specified with cgo).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcc &lt;span class="nt"&gt;-m64&lt;/span&gt; &lt;span class="nt"&gt;-shared&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; imgtype.dll imgtype.def libimgtype.a &lt;span class="nt"&gt;-Wl&lt;/span&gt;,--allow-multiple-definition &lt;span class="nt"&gt;-static&lt;/span&gt; &lt;span class="nt"&gt;-lwinmm&lt;/span&gt; &lt;span class="nt"&gt;-lntdll&lt;/span&gt; &lt;span class="nt"&gt;-lWs2_32&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to create a lib file
&lt;/h1&gt;

&lt;p&gt;The. lib file is done with the lib command attached to MSVC.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lib /machine:x64 /def:imgtype.def
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I am ready to integrate into MSVC mruby.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/kjunichi/libimgtype"&gt;https://github.com/kjunichi/libimgtype&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Calling Go from mruby
&lt;/h1&gt;

&lt;p&gt;If you come here, you only write mrbgem. Write the created. Lib file in mrbgem.rake as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;linker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flags_before_libraries&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s2"&gt;"imgtype.lib"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can pass the path to the imgtype.lib file to the environment variable LIB, and mruby.exe and mirb.exe can be created by incorporating Go library with rake.&lt;/p&gt;

&lt;h1&gt;
  
  
  To run
&lt;/h1&gt;

&lt;p&gt;This mrb gem is required below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gembox&lt;/span&gt; &lt;span class="s1"&gt;'default'&lt;/span&gt;
&lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'../mruby-webcam'&lt;/span&gt;
&lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'../mruby-imgtype'&lt;/span&gt;
&lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gem&lt;/span&gt; &lt;span class="ss"&gt;:github&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'matsumoto-r/mruby-sleep'&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is a mruby script that displays the webcam image at the command prompt or Vim: terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Imgtype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;

&lt;span class="n"&gt;cam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Webcam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="n"&gt;cam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setFmt&lt;/span&gt; &lt;span class="s2"&gt;"ppm"&lt;/span&gt;
&lt;span class="n"&gt;cam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;capture&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="no"&gt;Imgtype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;imgtype&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
    &lt;span class="n"&gt;cam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;snap&lt;/span&gt;
    &lt;span class="no"&gt;Sleep&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;usleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Imgtype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_key&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"ESC"&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="no"&gt;Imgtype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Result
&lt;/h1&gt;

&lt;p&gt;Imgtype.get_key reads Windows API directly and responds. I was surprised to get key input without polling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://t.co/gtYXg0tOA3"&gt;https://t.co/gtYXg0tOA3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>mruby</category>
      <category>windows</category>
      <category>go</category>
    </item>
    <item>
      <title>How to build plv8 on Windows</title>
      <dc:creator>Junichi Kajiwara</dc:creator>
      <pubDate>Wed, 15 Nov 2017 08:17:36 +0000</pubDate>
      <link>https://forem.com/kjunichi/how-to-build-plv8-on-windows-4d</link>
      <guid>https://forem.com/kjunichi/how-to-build-plv8-on-windows-4d</guid>
      <description>&lt;p&gt;This article is obsolete.&lt;a href="https://github.com/plv8/plv8/pull/272"&gt;Now officially plv8 supports for Windows!&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/plv8/plv8/pull/239"&gt;https://github.com/plv8/plv8/pull/239&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Let's try
&lt;/h1&gt;

&lt;p&gt;You need following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;vs2015/vs2017&lt;/li&gt;
&lt;li&gt;Postgres9.6&lt;/li&gt;
&lt;li&gt;git(and patch.exe)&lt;/li&gt;
&lt;li&gt;cmake&lt;/li&gt;
&lt;li&gt;nuget.exe
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/kjunichi/plv8.git
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;plv8
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout support-msvc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you have to patch to PostgreSQL's header file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;copy &lt;span class="s2"&gt;"c:&lt;/span&gt;&lt;span class="se"&gt;\P&lt;/span&gt;&lt;span class="s2"&gt;rogram Files&lt;/span&gt;&lt;span class="se"&gt;\P&lt;/span&gt;&lt;span class="s2"&gt;ostgreSQL&lt;/span&gt;&lt;span class="se"&gt;\9&lt;/span&gt;&lt;span class="s2"&gt;.6&lt;/span&gt;&lt;span class="se"&gt;\i&lt;/span&gt;&lt;span class="s2"&gt;nclude&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="s2"&gt;erver&lt;/span&gt;&lt;span class="se"&gt;\p&lt;/span&gt;&lt;span class="s2"&gt;ort&lt;/span&gt;&lt;span class="se"&gt;\a&lt;/span&gt;&lt;span class="s2"&gt;tomics&lt;/span&gt;&lt;span class="se"&gt;\g&lt;/span&gt;&lt;span class="s2"&gt;eneric-msvc.h"&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="nb"&gt;set &lt;/span&gt;&lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;%path%&lt;span class="p"&gt;;&lt;/span&gt;c:&lt;span class="se"&gt;\P&lt;/span&gt;rogram Files&lt;span class="se"&gt;\G&lt;/span&gt;it&lt;span class="se"&gt;\u&lt;/span&gt;sr&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="k"&gt;in
&lt;/span&gt;patch &lt;span class="nt"&gt;--binary&lt;/span&gt; &lt;span class="nt"&gt;-p1&lt;/span&gt; generic-msvc.h &amp;lt; generic-msvc.h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then,you copy patched generic-msvc.h to PostgreSQL's header file(c:\Program Files\PostgreSQL\9.6\include\server\port\atomics\generic-msvc.h).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;bootstrap.bat
&lt;span class="nv"&gt;$ &lt;/span&gt;cmake &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-G&lt;/span&gt; &lt;span class="s2"&gt;"Visual Studio 14 2015 Win64"&lt;/span&gt; &lt;span class="nt"&gt;-DCMAKE_INSTALL_PREFIX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"C:&lt;/span&gt;&lt;span class="se"&gt;\P&lt;/span&gt;&lt;span class="s2"&gt;rogram Files&lt;/span&gt;&lt;span class="se"&gt;\P&lt;/span&gt;&lt;span class="s2"&gt;ostgreSQL&lt;/span&gt;&lt;span class="se"&gt;\9&lt;/span&gt;&lt;span class="s2"&gt;.6"&lt;/span&gt; &lt;span class="nt"&gt;-DPOSTGRESQL_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;9.6
&lt;span class="nv"&gt;$ &lt;/span&gt;cmake &lt;span class="nt"&gt;--build&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--config&lt;/span&gt; Release &lt;span class="nt"&gt;--target&lt;/span&gt; Package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when building is success,you'll get this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plv8-2.1.0-postgresql-9.6-x64.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unzip it, and copy to PostgreSQL directories.&lt;/p&gt;

</description>
      <category>windows</category>
      <category>postgres</category>
      <category>v8</category>
    </item>
  </channel>
</rss>
