Skip to content

Instantly share code, notes, and snippets.

local networkVars =
{
lolScale = "float",
}
local orig_Player_OnCreate = Player.OnCreate
function Player:OnCreate(...)
orig_Player_OnCreate(self, ...)
self.lolScale = 1
end
@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 / 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 / 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 / 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 / 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
function Fluttershy(f, ...)
local decl = {...}
return function(...)
local arg = {...}
for arg_i = 1, math.ceil(#decl/2) do
if type(arg[arg_i]) ~= decl[arg_i*2-1] then
arg[arg_i] = decl[arg_i*2]
end
end
return f(unpack(arg))
@Deco
Deco / benchmark_FStrEq.lua
Created February 15, 2012 03:22
HL2:SB benchmark example
--======== Copyleft © 2010-2011, Team Sandbox, Some rights reserved. ========--
--
-- Purpose: Tests the speed of FStrEq vs "".__eq.
--
--===========================================================================--
local Count = 10000
local Time = engine.Time
local flTimeExecution
local print = print
@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)