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 fun = require 'fun' | |
| local C = ffi.C | |
| local function generator(iterator, rtuple) | |
| local res = C.box_iterator_next(iterator, rtuple) | |
| if res == -1 then | |
| box.error() |
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
| -- luacheck:ignore | |
| max = { | |
| req = 0, | |
| seq = 0, | |
| } | |
| local function next_req() | |
| max.req = max.req + 1 | |
| return max.req | |
| 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
| -- v: 1 | |
| local ffi = require 'ffi' | |
| local C = ffi.C | |
| ffi.cdef[[ | |
| typedef struct node { | |
| uint8_t nkids; | |
| struct node **kids; | |
| uint32_t sprefix; |
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
| -- I suggest to execute this script using lua5.3+ (for integer division) | |
| -- Algorithm was rewritten from https://www.lua.org/source/5.1/ltablib.c.html#auxsort | |
| local function sort(a, comp, l, u) | |
| while(l < u) do | |
| if comp(a[u], a[l]) then -- a[u] < a[l] | |
| a[u], a[l] = a[l], a[u] -- swap | |
| end | |
| if u-l == 1 then -- only 2 elements | |
| break |
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/luajit-5_1-2.1.0-beta3 | |
| local print = print | |
| local collectgarbage = collectgarbage | |
| local pairs = pairs | |
| local tostring = tostring | |
| local module = module | |
| do | |
| for k in pairs(package) 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
| package main | |
| import "fmt" | |
| type IFace interface { | |
| Method() string | |
| } | |
| func TakingObject(i IFace) { | |
| fmt.Println(i.Method()) |
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 _1 = 1 | |
| local _2 = 2 | |
| local _3 = 3 | |
| local _4 = 4 | |
| local _5 = 5 | |
| local _6 = 6 | |
| local _7 = 7 | |
| local _8 = 8 | |
| local _9 = 9 | |
| local _10 = 10 |
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 a_1 = 1 | |
| local a_2 = 2 | |
| local a_3 = 3 | |
| local a_4 = 4 | |
| local a_5 = 5 | |
| local a_6 = 6 | |
| local a_7 = 7 | |
| local a_8 = 8 | |
| local a_9 = 9 | |
| local a_10 = 10 |
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
| -- Code was taken from http://leafo.net/guides/dynamic-scoping-in-lua.html | |
| function dynamic(name) | |
| local level = 2 | |
| -- iterate over | |
| while true do | |
| if not debug.getinfo(level) then | |
| -- check that we didn't leave the call-stack | |
| break | |
| end | |
| local i = 1 |
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 class = require 'metaclass' | |
| local class1 = class "Person" | |
| print(class1) | |
| function class.Person:sayHello( ... ) | |
| print(self, "Hello!") | |
| end | |
| function class1:HelloMazafaka( ... ) |