annotate src/lib/Utils.luan @ 19:b386303be994

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 02 Nov 2023 21:00:37 -0600
parents af2b95854072
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local set_metatable = Luan.set_metatable or error()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Http = require "luan:http/Http.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Utils = {}
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 function Utils.get_user()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 return Http.request.cookies.user
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 end
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local set_mt = {}
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 function set_mt.__index(table,key)
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 return false
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 end
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 function Utils.list_to_set(list)
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local set = {}
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 for _, v in ipairs(list) do
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 set[v] = true
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 set_metatable(set,set_mt)
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return set
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 return Utils