Skip to content

Instantly share code, notes, and snippets.

@ericroy
ericroy / ntp.lua
Last active April 30, 2017 01:32
NTP time check using lua socket
-- Most of this came from the blog article here:
-- https://lettier.github.io/posts/2016-04-26-lets-make-a-ntp-client-in-c.html
-- For reference, the packet structure looks like:
--[[
typedef struct
{
unsigned li : 2; // Only two bits. Leap indicator.
unsigned vn : 3; // Only three bits. Version number of the protocol.
unsigned mode : 3; // Only three bits. Mode. Client will pick mode 3 for client.
@ericroy
ericroy / example_scene_manager.lua
Last active March 15, 2017 06:05
Usage example for saga.lua
local saga = require('lib.saga')
local function switch_scene(self, next_scene)
-- Unload the current scene (if there is one)
if self.scene then
local proxy_id = '#' .. self.scene
print('Unloading proxy: ' .. proxy_id)
msg.post(proxy_id, 'disable')
msg.post(proxy_id, 'final')
@ericroy
ericroy / saga.lua
Created March 15, 2017 05:39
Simple saga-like pattern in Lua for Defold
local M = {}
local traceback = debug.traceback
local yield = coroutine.yield
local resume = coroutine.resume
local create = coroutine.create
local status = coroutine.status
function M.create(f, ...)
local co = create(f)