Coder Social home page Coder Social logo

agulev / jstodef Goto Github PK

View Code? Open in Web Editor NEW
37.0 6.0 7.0 51 KB

Library for sending messages from JavaScript to Defold (Lua)

License: MIT License

HTML 33.44% JavaScript 17.71% C++ 44.81% Lua 4.03%
defold defold-game-engine defold-library lua emscripten

jstodef's Introduction

JsToDef

Build Status

This is Native Extension for the Defold Game Engine that makes possible to send messages from JavaScript to Lua in HTML5 build.

Installation

To use this library in your Defold project, add the needed version URL to your game.project dependencies from Releases

image

API JavaScript side

JsToDef.send(message_id, message)

Where message_id is a string that helps you to identify this message on Lua side.

message is a custom value that might be one of the next types: object, number, boolean, string, undefined(if you don't need any extra data).

Example:
JsToDef.send("MyCustomMessageName", "custom message");
JsToDef.send("ObjectEvent", {foo:"bar", num:16, isAv:true});
JsToDef.send("FloatEvent", 19.2);
JsToDef.send("IntEvent", 18);
JsToDef.send("StrintEvent", "custom string");
JsToDef.send("EmptyEvent");
JsToDef.send("BooleanEvent", true);
JsToDef.send("BooleanEvent", false);

API Lua side

If you are working on cross-platform application the best practice to check the existence of jstodef module, this module exists only in html5 build:

if jstodef then
  -- any operations with jstodef
end

Add Listener

jstodef.add_listener(listener)

Where listener is a function with the next parameters:

self is the current script self.

message_id is a string that helps you to identify this message.

message is a custom value that might be one of the next types: table, number, boolean, string, nil.

It is possible to add a few listeners.

Example:
local function js_listener(self, message_id, message)
  if message_id == "MyCustomMessageName" then
    -- do something
  end
end

function init(self)
  if jstodef then
    jstodef.add_listener(js_listener)
  end
end

Remove Listener

jstodef.remove_listener(listener)

Where listener is the function that was previously added as a listener with jstodef.add_listener() method.

function final(self)
  if jstodef then
    jstodef.remove_listener(js_listener)
  end
end

Issues and suggestions

If you have any issues, questions or suggestions please create an issue or contact me: [email protected]

jstodef's People

Contributors

aglitchman avatar agulev avatar ekharkunov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jstodef's Issues

Callbacks both ways useful?

I feel like this supporting sending messages / doing callbacks going both ways out of the box would be useful.

Defold 1.2.178 dynCall error

Hi @AGulev I am getting this error:
Uncaught ReferenceError: dynCall is not defined

It only started after upgrading to the latest 1.2.178 Defold version. Probably related to the Emscripten update?

How can this be fixed?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.