Skip to content

Instantly share code, notes, and snippets.

@Deco
Deco / luajit_benchmark_callback.lua
Created September 8, 2012 10:58
Benchmark of C callbacks in LuaJIT 2.0.0-beta10
local ffi = require"ffi"
jit.on()
ffi.cdef[[
typedef int (*getval_func)();
/* imagine these are C functions */
typedef void (*sum_push_func)(int* total, getval_func getval);
typedef void (*sum_pull_func)(int* total, int val);
]]
@Deco
Deco / deepcopy.lua
Created October 31, 2012 05:38
Lua Non-recursive Deep-copy
--[[ deepcopy.lua
Deep-copy function for Lua - v0.2
==============================
- Does not overflow the stack.
- Maintains cyclic-references
- Copies metatables
- Maintains common upvalues between copied functions (for Lua 5.2 only)
TODO
@Deco
Deco / socketlanes.lua
Created November 6, 2012 17:39
Multi-threaded LuaSocket with Lua Lanes example
--[[ socketlanes.lua
Multi-threaded LuaSocket with Lua Lanes example
===============================================
Depends on the following LuaSocket 2.0.2 patch:
http://www.net-core.org/dl/luasocket-2.0.2-acceptfd.patch
(via http://www.net-core.org/39/lua/patching-luasocket-to-make-it-compatible)
(provided at end of file)
@Deco
Deco / coroutine_scheduler.lua
Created February 13, 2012 16:38
Lua Coroutine Scheduler
pcall(require,"socket")
local coroutine_scheduler = {
_NAME = "coroutine_scheduler.lua"
_VERSION = "1.0.0",
}
local Scheduler
do Scheduler = setmetatable({}, {
__call = function(class)
@Deco
Deco / geometry.lua
Created February 2, 2012 08:18 — forked from Deco/geometry.lua
Luvit module example (using local _M table) (my personal choice)
local OO = require"oo"
local _M = {}
do _M.Shape = OO.class({
})
function _M.Shape:__init()
error("attempt to instantiate abstract shape")
end
#[allow(unused_imports)]
use std::sync::Arc;
#[allow(unused_imports)]
use std::vec::IntoIter as VecIntoIter;
#[allow(unused_imports)]
use vulkano::device::Device;
#[allow(unused_imports)]
use vulkano::descriptor::descriptor::DescriptorDesc;
extern crate time;
#[derive(Debug, Clone)]
struct Vertex { position: [f32; 2], velocity: [f32; 2] }
fn main() {
let mut arr = vec![ Vertex { position: [0.0, 0.0], velocity: [0.0, 0.0] }; 200000 ];
@Deco
Deco / lua\LBAL_Server.lua
Created November 2, 2013 14:19
Lucas's Balance Mod Example
--[[ ]]
function SetLocal(func, name, value)
local index = 1
local foundIndex = nil
while true do
local n, v = debug.getupvalue(func, index)
if not n then
break
end
@Deco
Deco / contourplot.lua
Created June 9, 2013 01:25
Live recursive contour plotting for Lua
local function contourPlot(func, lf, x, y, w, h, interval, offset, mindepth, maxdepth, dbg, depth, fvbr, fvbl, fvtl, fvtr)
local wh, hh = w/2, h/2
local v_c = func(x+wh, y+hh)+offset
local v_br = fvbr or func(x+w , y+h )+offset
local v_bl = fvbl or func(x , y+h )+offset
local v_tl = fvtl or func(x , y )+offset
local v_tr = fvtr or func(x+w , y )+offset
local linelist, linecount, v = {}, 1
@Deco
Deco / debug_getparams.lua
Created May 6, 2012 17:59
debug.getparams
function debug.getparams(f)
local co = coroutine.create(f)
local params = {}
debug.sethook(co, function(event, line)
local i, k, v = 1, debug.getlocal(co, 2, 1)
while k do
if k ~= "(*temporary)" then
table.insert(params, k)
end
i = i+1