@bekti/

C QUEUE simpleExample in WASM

HTML, CSS, JS

http://bekti.net/blog/mengenal-web-assembly-dengan-c/

fork
loading
Files
  • index.html
  • queue.c
  • queue.js
  • queue.wasm

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.4395351360468265","path":"index.html","file":{"path":"index.html","content":{"asEncoding":{"base64":"PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KPGhlYWQ+CiAgPG1ldGEgY2hhcnNldD0iVVRGLTgiPgogIDxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgsIGluaXRpYWwtc2NhbGU9MS4wIj4KICA8bWV0YSBodHRwLWVxdWl2PSJYLVVBLUNvbXBhdGlibGUiIGNvbnRlbnQ9ImllPWVkZ2UiPgogIDx0aXRsZT5Qcm9ncmFtIFF1ZXVlIE1lbmdndW5ha2FuIFdBU008L3RpdGxlPgo8L2hlYWQ+Cjxib2R5PgogIDxkaXYgaWQ9Im91dHB1dCIgcm93cz0iOCI+PC9kaXY+CiAgPGJ1dHRvbiBpZD0iZW5xdWV1ZSI+ZW5xdWV1ZTwvYnV0dG9uPiAKICA8YnV0dG9uIGlkPSJkZXF1ZXVlIj5kZXF1ZXVlPC9idXR0b24+IAogIDxzY3JpcHQ+CiAgICB2YXIgZW5xdWV1ZSA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdlbnF1ZXVlJyk7CiAgICB2YXIgZGVxdWV1ZSA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdkZXF1ZXVlJyk7CgogICAgZW5xdWV1ZS5hZGRFdmVudExpc3RlbmVyKCdjbGljaycsIGZ1bmN0aW9uKCl7CiAgICAgIHZhciBkYXRhID0gcHJvbXB0KCJUYW1iYWhrYW4gRGF0YSBRdWV1ZSA6IiwgIiIpOwogICAgICBfZW5xdWV1ZShkYXRhKTsKICAKICAgIH0pOwoKICAgIGRlcXVldWUuYWRkRXZlbnRMaXN0ZW5lcignY2xpY2snLCBmdW5jdGlvbigpewogICAgIF9kZXF1ZXVlKCk7CiAgICB9KTsKCiAgICAoZnVuY3Rpb24gKCkgewogICAgdmFyIG9sZCA9IGNvbnNvbGUubG9nOwogICAgdmFyIGxvZ2dlciA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdvdXRwdXQnKTsKICAgIGNvbnNvbGUubG9nID0gZnVuY3Rpb24gKCkgewogICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGFyZ3VtZW50cy5sZW5ndGg7IGkrKykgewogICAgICAgIGlmICh0eXBlb2YgYXJndW1lbnRzW2ldID09ICdvYmplY3QnKSB7CiAgICAgICAgICAgIGxvZ2dlci5pbm5lckhUTUwgPSAoSlNPTiAmJiBKU09OLnN0cmluZ2lmeSA/IEpTT04uc3RyaW5naWZ5KGFyZ3VtZW50c1tpXSwgdW5kZWZpbmVkLCAyKSA6IGFyZ3VtZW50c1tpXSkgKyAnPGJyIC8+JzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBsb2dnZXIuaW5uZXJIVE1MID0gYXJndW1lbnRzW2ldICsgJzxiciAvPic7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICB9KSgpOwogIDwvc2NyaXB0PiAKICA8c2NyaXB0IGFzeW5jIHR5cGU9InRleHQvamF2YXNjcmlwdCIgc3JjPSJxdWV1ZS5qcyI+PC9zY3JpcHQ+CjwvYm9keT4KPC9odG1sPg=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Program Queue Menggunakan WASM</title>
</head>
<body>
  <div id="output" rows="8"></div>
  <button id="enqueue">enqueue</button> 
  <button id="dequeue">dequeue</button> 
  <script>
    var enqueue = document.getElementById('enqueue');
    var dequeue = document.getElementById('dequeue');

    enqueue.addEventListener('click', function(){
      var data = prompt("Tambahkan Data Queue :", "");
      _enqueue(data);
  
    });

    dequeue.addEventListener('click', function(){
     _dequeue();
    });

    (function () {
    var old = console.log;
    var logger = document.getElementById('output');
    console.log = function () {
      for (var i = 0; i < arguments.length; i++) {
        if (typeof arguments[i] == 'object') {
            logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(arguments[i], undefined, 2) : arguments[i]) + '<br />';
        } else {
            logger.innerHTML = arguments[i] + '<br />';
        }
      }
    }
    })();
  </script> 
  <script async type="text/javascript" src="queue.js"></script>
</body>
</html>
result
console