All Projects → AGulev → jstodef

AGulev / jstodef

Licence: MIT license
Library for sending messages from JavaScript to Defold (Lua)

Programming Languages

C++
36643 projects - #6 most used programming language
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
lua
6591 projects

Projects that are alternatives of or similar to jstodef

defos
Extra native OS functions for games written using the Defold game engine
Stars: ✭ 64 (+204.76%)
Mutual labels:  defold-game-engine, defold, defold-library
extension-fbinstant
Facebook Instant Games extension for the Defold game engine
Stars: ✭ 39 (+85.71%)
Mutual labels:  defold-game-engine, defold, defold-library
defold-hyper-trails
Easy to use and customizable trail effect for the Defold game engine.
Stars: ✭ 33 (+57.14%)
Mutual labels:  defold-game-engine, defold, defold-library
defold-eva
Basic defold module for mobile games
Stars: ✭ 21 (+0%)
Mutual labels:  defold-game-engine, defold, defold-library
defold-playable-ads
Make playable ads with Defold! It's a project with Gulp tasks to bundle the Defold game into a single HTML file.
Stars: ✭ 15 (-28.57%)
Mutual labels:  defold-game-engine, defold, defold-library
DefVideoAds
UnityAds native extension for Defold engine.
Stars: ✭ 37 (+76.19%)
Mutual labels:  defold-game-engine, defold, defold-library
DAABBCC
Dynamic AABB Tree native extension with Branch and Bound Algorithm for Defold Engine
Stars: ✭ 42 (+100%)
Mutual labels:  defold-game-engine, defold, defold-library
drawpixels
Defold engine native extension for drawing pixels into texture buffer.
Stars: ✭ 46 (+119.05%)
Mutual labels:  defold-game-engine, defold, defold-library
defold-router
whDefRouter — screen management solution for Defold Game Engine (includes demo project)
Stars: ✭ 25 (+19.05%)
Mutual labels:  defold-game-engine, defold
defold-input
Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects
Stars: ✭ 67 (+219.05%)
Mutual labels:  defold, defold-library
defold-richtext
Defold-RichText is a system to create styled text based on an HTML inspired markup language
Stars: ✭ 35 (+66.67%)
Mutual labels:  defold, defold-library
defold-metrics
Calculate and display performance metrics in Defold games
Stars: ✭ 23 (+9.52%)
Mutual labels:  defold, defold-library
platypus
Defold platformer engine
Stars: ✭ 31 (+47.62%)
Mutual labels:  defold, defold-library
defold-deployer
Universal build && deploy script for Defold projects
Stars: ✭ 23 (+9.52%)
Mutual labels:  defold-game-engine, defold
defnet
Defold networking examples
Stars: ✭ 52 (+147.62%)
Mutual labels:  defold, defold-library
extension-admob
Defold native extension which provides access to AdMob functionality on Android and iOS
Stars: ✭ 31 (+47.62%)
Mutual labels:  defold, defold-library
extension-gpgs
Defold native extension for Google Play Game Services
Stars: ✭ 19 (-9.52%)
Mutual labels:  defold, defold-library
defpro
Defold Profiler interaction using Lua
Stars: ✭ 19 (-9.52%)
Mutual labels:  defold, defold-library
defold-sharing
Defold native extension to share data from a Defold application using native dialogs
Stars: ✭ 20 (-4.76%)
Mutual labels:  defold, defold-library
gooey
Defold GUI system
Stars: ✭ 99 (+371.43%)
Mutual labels:  defold, defold-library

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.

Setup

You can use the JsToDef extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/AGulev/jstodef/archive/master.zip

Or point to the ZIP file of a specific release.

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]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].