Skip to content

Instantly share code, notes, and snippets.

View britzl's full-sized avatar
💭
Making Defold even better!

Björn Ritzl britzl

💭
Making Defold even better!
View GitHub Profile
@britzl
britzl / cla.txt
Created April 23, 2019 09:04
Trying out cla-assistant.io for the public Defold repos
Thank you for your interest in Defold. In order to clarify the intellectual property license granted with Contributions from any person or entity, Defold must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Defold and its users; it does not change your rights to use your own Contributions for any other purpose.
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Defold. Except for the license granted herein to Defold and recipients of software distributed by Defold, You reserve all right, title, and interest in and to Your Contributions.
1. Definitions.
"You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Defold. For legal entities, the entity making a Contribution and all other entities that
@britzl
britzl / luautils.cpp
Last active September 1, 2019 14:02
Lua C utility functions for manipulating the stack and setting up listeners
#include <dmsdk/sdk.h>
#include "luautils.h"
void luaL_checklistener(lua_State* L, int idx, struct lua_Listener& listener) {
int top = lua_gettop(L);
luaL_checktype(L, idx, LUA_TFUNCTION);
lua_pushvalue(L, idx);
int cb = dmScript::Ref(L, LUA_REGISTRYINDEX);
if (listener.m_Callback != LUA_NOREF) {
@britzl
britzl / tinted_label.fp
Last active May 19, 2019 09:28
DEPRECATED - How to tint labels in Defold
varying mediump vec2 var_texcoord0;
varying lowp vec4 var_face_color;
varying lowp vec4 var_outline_color;
varying lowp vec4 var_shadow_color;
uniform lowp vec4 texture_size_recip;
uniform lowp sampler2D texture;
uniform lowp vec4 tint;
void main()
@britzl
britzl / bundle.sh
Last active December 10, 2020 13:45
Script to build and bundle a Defold project for multiple platforms
#!/bin/bash
title=$(less game.project | grep "^title = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
title_no_space=$(echo -e "${title}" | tr -d '[[:space:]]')
echo "Project: ${title}"
if [ ! -f bob.jar ]
then
echo "Unable to find bob.jar. Download it from d.defold.com."
exit 1
@britzl
britzl / timer.lua
Last active February 13, 2018 14:18
Timer module that can be used to get a callback when a certain amount of time has elapsed
--- Module that can be used to get a callback when a certain amount of time has elapsed
--
-- @usage
-- local timer = require "timer"
-- function init(self)
-- self.t1 = timer.seconds(2, function()
-- print("2 seconds have elapsed")
-- end)
-- self.t2 = timer.seconds(5, function()
-- print("5 seconds have elapsed")
@britzl
britzl / luabindown.sh
Created August 25, 2014 05:36
Shell script to download an OS specific Lua 5.1 binary
#!/bin/bash
# Downloads an OS specific Lua 5.1 binary
if [[ "$OSTYPE" == "linux-gnu" ]]; then
LUA_DOWNLOAD_URL="http://sourceforge.net/projects/luabinaries/files/5.1.5/Tools%20Executables/lua-5.1.5_Linux32_64_bin.tar.gz/download"
LUA_BINARY=lua5.1
elif [[ "$OSTYPE" == "darwin"* ]]; then
LUA_DOWNLOAD_URL="http://sourceforge.net/projects/luabinaries/files/5.1.5/Tools%20Executables/lua-5.1.5_MacOS109_bin.tar.gz/download"
LUA_BINARY=lua5.1
elif [[ "$OSTYPE" == "win32" ]]; then
# from http://stackoverflow.com/a/8597411/1266551
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# ...
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
@britzl
britzl / gdump.lua
Last active August 29, 2015 14:05
Dump contents of global table
local function gdump()
local function dump_table(t, indentation)
indentation = indentation or ""
local table_model = {}
for k,v in pairs(t) do
table_model[type(v)] = table_model[type(v)] or {}
table_model[type(v)][k] = v
end
for type,_ in pairs(table_model) do
print(indentation .. type .. ":")
@britzl
britzl / superstrict.lua
Last active August 29, 2015 14:02
Lua strict mode variant with a whitelist for allowed names
--- A module for guarding tables from new indices. Typical use is to guard the global scope.
-- Get the latest version from https://gist.github.com/britzl/546d2a7e32a3d75bab45
-- @module superstrict
-- @usage
--
-- -- Defold specific example. Allow the gameobject and gui script lifecycle functions. Also allow assignment of
-- -- facebook and iap modules for dummy implementations on desktop. The whitelist handles pattern matching and in the
-- -- example all functions prefixed with '__' will also be allowed in the global scope
-- local superstrict = require("superstrict")
-- superstrict.lock(_G, { "go", "gui", "msg", "url", "sys", "render", "factory", "particlefx", "physics", "sound", "sprite", "image", "tilemap", "vmath", "matrix4", "vector3", "vector4", "quat", "hash", "hash_to_hex", "hashmd5", "pprint", "iap", "facebook", "push", "http", "json", "spine", "zlib", "init", "final", "update", "on_input", "on_message", "on_reload", "__*" })
@britzl
britzl / keybase.md
Created May 13, 2014 21:47
keybase.md

Keybase proof

I hereby claim:

  • I am britzl on github.
  • I am britzl (https://keybase.io/britzl) on keybase.
  • I have a public key whose fingerprint is 0550 F9F9 695B AA0E C6A3 E29E 081A 6067 688C FEA3

To claim this, I am signing this object: