This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | |
| -- Reverses an ipairs table | |
| -- | |
| --local r = ReverseTable({'a', 'b', 'c'}) | |
| --for k, v in ipairs(r) do | |
| -- print(k, v) | |
| --end | |
| -- | |
| -- | |
| function ReverseTable(t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function AllCombinations(list, stop) | |
| stop = stop or #list | |
| if stop == 0 then | |
| return list | |
| end | |
| local collect = {} | |
| for k, v in pairs(list) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function AllCombinations(list, stop) | |
| stop = stop or #list | |
| if stop == 0 then | |
| return list | |
| end | |
| local collect = {} | |
| for k, v in pairs(list) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "cstdio" | |
| // No type information | |
| class ClassMeta | |
| { | |
| class Holder | |
| { | |
| public: | |
| virtual void* GetPtr() const { return NULL; } | |
| protected: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function WrapZeroOne(value) | |
| value = value - math.floor(value) | |
| if value < 0 then | |
| x = x + 1 | |
| end | |
| return value | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | |
| -- In C style languages you can cyclically access elements of an array using the modulus operator | |
| -- | |
| -- Lua-style psuedo code: | |
| -- | |
| -- array = {'a', 'b', 'c', 'd'}; | |
| -- i = 0; | |
| -- while true do | |
| -- print(array[i % array.count()]); | |
| -- i++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Stats = {} | |
| Stats.__index = Stats | |
| function Stats:Create(stats) | |
| local this = | |
| { | |
| mBase = {}, | |
| mModifiers = {} | |
| } | |
| -- Shallow copy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OddmentTable<T> | |
| { | |
| // Allows comparison of generic types. | |
| //See: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=193203&SiteID=1 | |
| private static readonly IEqualityComparer<T> comparer = | |
| EqualityComparer<T>.Default; | |
| protected List<Entry> entries = new List<Entry>(); | |
| protected int oddment = 0; | |
| protected Random random; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static float LerpF( float value, float in0, float in1, float out0, float out1 ) | |
| { | |
| float normed = (value - in0) / (in1 - in0); | |
| float result = out0 + (normed * (out1 - out0)); | |
| return result; | |
| } |
OlderNewer