NaCl tips; NaClã¢ã¸ã¥ã¼ã« <==> JavaScript ã¡ãã»ã¼ã¸ã³ã°
èªåèªèº«ãä½ãããã¨æã£ã¦ããã²ã¼ã ã®ã¢ã¤ãã¢ãå®ç¾ããããæè¡çãªãã¹ãããªã³ã©ã¤ã³ã§è¡ããã©ãããã©ã¼ã ã¨ãã¹ãã
"Labyrinthian - Wonder Rabbit Project"
ãå®è£
ãå§ãã¾ãããå®è£
ã¨ããããã¹ããã¦ãã ããªæãã§ããã©ã
source
NaClã¢ã¸ã¥ã¼ã«ã¨JavaScriptã®éã§ã¡ãã»ã¼ã¸ã³ã°ã確èªããç¶æ ã«èªåç¨åå¿é²ã¨ãã¦ã¡ã¢ãéºãã¦ããäºã«ã
tips
JavaScript side
- NaClã¢ã¸ã¥ã¼ã«ããã¹ãããembedè¦ç´ ã®`message`ã¤ãã³ãã«NaClã¢ã¸ã¥ã¼ã«ããã®ã¡ãã»ã¼ã¸ãå±ã
- 第ï¼ãã©ã¡ã¼ã¿ã«ã¡ãã»ã¼ã¸ãå ¥ã£ã¦ããã®ã§é©å®ã«åãåã
- NaClã¢ã¸ã¥ã¼ã«ããã¹ãããembedè¦ç´ ã®`postMessage`é¢æ°ã§NaClã¢ã¸ã¥ã¼ã«ã¸ã®ã¡ãã»ã¼ã¸ãéã
- 第ï¼ãã©ã¡ã¼ã¿ã«ã¡ãã»ã¼ã¸ãæ¾ãè¾¼ãã°è¯ã
- `message`ã`postMessage`ã¯embedã®NaClã¢ã¸ã¥ã¼ã«ãèªã¿è¾¼ã¿ãå®äºãã¦ããªããã°çºåã§ããªããããå½ç¶ãã®è¦ç´ ã®`load`ã¤ãã³ãã®çºè¡ãããå¾ã§ãªããã°ä½¿ããªãã
NaCl side
- #include "ppapi/cpp/var.h"
- èªããªã: nacl_sdk/pepper_19/toolchain/linux_x86_newlib/x86_64-nacl/include/ppapi/cpp/var.h
- `pp::Var`åã¯ã¡ãã»ã¼ã¸ã®éåä¿¡ã«ç¨ããã´ã¡ãªã¢ã³ãå
- åºæ¬çãªãã¼ã¿ã¨ãã¦ã¯ `bool` `int32_t` `double` `const char*` `const std::string&` ãæ±ããï¼æååã¯ä½ããUTF-8ãæ³å®ãï¼
- JSåºæã® `undefined` `null` `object` ãæ±ããã
- `is_undefined` `is_object` `is_bool` `is_int` `is_string` `is_number` ãªã©ã®ã¡ã³ãã¼é¢æ°ã«ããå å ããåãå¤å®ã§ããã
- `AsBool` `AsInt` `AsDouble` `AsString` ã«ãã C++ ãæ¨æºçã«æ±ããåã§ä¸èº«ãåãåºããã
- `Var(const Var&)`ã³ã³ã¹ãã©ã¯ã¿ã¼ã¨`virtual Var& operator=(const Var&)`ç ´å£ç代å
¥æ¼ç®åãå®è£
ããã¦ããã
- `bool` `int32_t` `double` `const char*` `const std::string&`ã«å¯¾å¿ããã³ã³ã¹ãã©ã¯ã¿ã¼ãæã£ã¦ããã
- `bool operator==(const Var&) const`ç価æ§æ¯è¼æ¼ç®åãå®è£ ããã¦ããã
- `pp::Instance`ãpublicç¶æ¿ããNaClã¤ã³ã¹ã¿ã³ã¹ã¯ã©ã¹ã®ã¡ã³ãã¼ä»®æ³é¢æ°`virtual void HandleMessage(const pp::Var&)`ã«JavaScriptããNaClã¢ã¸ã¥ã¼ã«ã¸éåºãããã¡ãã»ã¼ã¸ãå±ãã
- `pp::Instance`ãpublicç¶æ¿ããNaClã¤ã³ã¹ã¿ã³ã¹ã¯ã©ã¹ãç¶æ¿ããã¡ã³ãã¼é¢æ°`void PostMessage(const pp::Var&)`ã§JavaScriptã¸ã®ã¡ãã»ã¼ã¸ãéåºããã