Skip to content

Instantly share code, notes, and snippets.

@balaam
balaam / PrintTable
Created March 2, 2014 06:46
Everyone writes a PrintTable function in Lua. This one is mind. It's written with the idea of encoding using the same code - like printing to JSON for instance.
--
-- Call PrintTable on a table to print a nicely formated lua table to the console.
-- The print table can also be overloaded with a different type of printer to output the table in a new representation
-- like a blob.
--
-- In the final version both these should be changed to local
TabSize = 4
DataType =
using System;
using System.Collections.Generic;
public class Program
{
enum eStat
{
HPNow,
HPMax,
<!DOCTYPE html>
<html>
<head>
<script>
glyphs = [
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], // padding
[0, 0, 0, 0, 0, 0, 0, 0], // , 32
[8, 8, 8, 8, 8, 0, 8, 0], // !, 33
[20, 20, 20, 0, 0, 0, 0, 0], // ", 34
<!DOCTYPE html>
<html>
<head>
<script>
function isBitOn(number, index) {
return Boolean(number & (1 << index));
}
window.onload = function() {
var canvas = document.getElementById('canvas');
alias night="pmset displaysleepnow && osascript -e \"set volume output volume 34\""
Stats = {}
Stats.__index = Stats
function Stats:Create(stats)
local this =
{
mBase = {},
mModifiers = {}
}
-- Shallow copy
@balaam
balaam / JRPG - Levels
Created February 5, 2014 11:59
Example code for a levelling up system in a JRPG. As explained on my blog http://www.godpatterns.com and upcoming book: www.howtomakeanrpg.com
function nextLevel(level)
local exponent = 1.5
local baseXP = 1000
return math.floor(baseXP * (level ^ exponent))
end
Stats = {}
Stats.__index = Stats
function Stats:Create(stats)
local this =
@balaam
balaam / reverseTable.lua
Created July 16, 2012 10:59
Reverse an ipairs table in Lua (not clever O(n) could be O(n/2) with swapping)
--
-- Reverses an ipairs table
--
--local r = ReverseTable({'a', 'b', 'c'})
--for k, v in ipairs(r) do
-- print(k, v)
--end
--
--
function ReverseTable(t)
@balaam
balaam / Watch.lua
Created October 4, 2016 07:45
A Lua project for Dinodeck that lets the user explore the global memory space
Watch = {}
Watch.__index = Watch
function Watch:Create()
local this =
{
key = {},
keyRoot =
{
id = "_G",
cursor = 1,
using System;
using System.Collections;
using System.Collections.Generic;
class MainClass {
public static void PrintList<T>(List<T> l)
{
for (int i = l.Count - 1; i >= 0 ; i--)