web.jslib 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. mergeInto(LibraryManager.library, {
  2. Hello: function () {
  3. window.alert("Hello, world!");
  4. },
  5. HelloString: function (str) {
  6. // window.alert(Pointer_stringify(str));
  7. window.alert(UTF8ToString(str));
  8. },
  9. PrintFloatArray: function (array, size) {
  10. for(var i = 0; i < size; i++)
  11. console.log(HEAPF32[(array >> 2) + i]);
  12. },
  13. AddNumbers: function (x, y) {
  14. return x + y;
  15. },
  16. StringReturnValueFunction: function () {
  17. var returnStr = "bla";
  18. var bufferSize = lengthBytesUTF8(returnStr) + 1;
  19. var buffer = _malloc(bufferSize);
  20. stringToUTF8(returnStr, buffer, bufferSize);
  21. return buffer;
  22. },
  23. BindWebGLTexture: function (texture) {
  24. GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[texture]);
  25. },
  26. Connect: function (host, port, clientId, username, password, destination) {
  27. mqttConnect(UTF8ToString(host), UTF8ToString(port), UTF8ToString(clientId), UTF8ToString(username), UTF8ToString(password), UTF8ToString(destination));
  28. },
  29. Subscribe: function (topic) {
  30. mqttSubscribe(UTF8ToString(topic))
  31. },
  32. Send: function (topic, payload) {
  33. mqttSend(UTF8ToString(topic), UTF8ToString(payload))
  34. },
  35. Unsubscribe: function(topic) {
  36. mqttUnsubscribe(UTF8ToString(topic));
  37. },
  38. Disconnect: function() {
  39. mqttDisconnect();
  40. }
  41. });