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
local times = 100000 | |
local start = os.clock() | |
for i=1,times do | |
local closure = function() | |
print("test") | |
end | |
end | |
print(os.clock() - start) |
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
local function locals(n) | |
n = n + 1 | |
local result = {} | |
for i=1,math.huge do | |
name, value = debug.getlocal(n, i) | |
if not name then break end | |
result[name] = {value} | |
end | |
return result | |
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
#!/usr/bin/env luajit | |
local c = require 'ansicolors' | |
local pegasus = require 'pegasus' | |
local http = require 'socket.http' | |
local ip = http.request('http://darkwiiplayer.com/api/ip') | |
math.randomseed(os.time()) |
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
local ffi = require 'ffi' | |
local intidx_fnc do | |
if ffi.abi('le') then | |
function intidx_fnc(n) | |
if n<1 or n>4 then | |
error("wrong index", 2) | |
end | |
return n-1 | |
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
local stdio = terralib.includec 'stdio.h' | |
local lua = terralib.includec 'lua.h' | |
-- lua_tolstring expects a size_t, which terra doesn't know. | |
local lua_length = lua.lua_tolstring:gettype().parameters[3].type | |
-- Fixed by introspecting the function and just reading the type | |
local terra hello(L : &lua.lua_State) | |
var len : lua_length; | |
var string : rawstring; |
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
local num = 2e6 -- 2e4 | |
print("Running with "..math.floor(tostring(num)).." Coroutines\n") | |
local threads = {} | |
local t1 = os.clock() | |
for i=1,num do | |
-- Creates a closure for every coroutine | |
-- The optimization is trivial, but was left out to be fair, as ruby deals poorly with lambdas |
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
local function element(name) | |
return function(tab) | |
return function() | |
print('<'..name..'>') | |
if type(tab) == 'table' then | |
for key, value in ipairs(tab) do | |
value() | |
end | |
elseif type(tab) == 'string' then | |
print(tab) |
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
local function tmap(tab, func) | |
local new = {} | |
for key, value in pairs(tab) do | |
new[key] = func(value) | |
end | |
return new | |
end | |
local terra add(a : int, b : int) | |
return a + b |
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
local doubles do | |
local function iter(tab, current) | |
local index = (current+1)*2 | |
local first, second = tab[index-1], tab[index] | |
if first and second then | |
return current+1, first, second | |
else | |
return | |
end | |
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
local lfs = require 'lfs' | |
local commands = {} | |
setmetatable(commands, {__call = function(self, name, func, description) | |
if func then | |
self[name] = func | |
table.insert(self, {name=name, description=description}) | |
else | |
for index, command in ipairs(self) do | |
print(command.name .. ': ' .. command.description) |