Skip to content

Commit

Permalink
unpack compat
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Sep 20, 2020
1 parent 80bc89b commit d3a16d1
Show file tree
Hide file tree
Showing 42 changed files with 71 additions and 9 deletions.
1 change: 1 addition & 0 deletions lapis/application.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Router = require("lapis.router").Router
local insert
insert = table.insert
local json = require("cjson")
local unpack = unpack or table.unpack
local capture_errors, capture_errors_json, respond_to
local run_before_filter
run_before_filter = function(filter, r)
Expand Down
2 changes: 2 additions & 0 deletions lapis/application.moon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import insert from table

json = require "cjson"

unpack = unpack or table.unpack

local capture_errors, capture_errors_json, respond_to

run_before_filter = (filter, r) ->
Expand Down
1 change: 1 addition & 0 deletions lapis/cmd/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ end
local default_environment
default_environment = require("lapis.environment").default_environment
local colors = require("ansicolors")
local unpack = unpack or table.unpack
local Actions
do
local _class_0
Expand Down
2 changes: 2 additions & 0 deletions lapis/cmd/actions.moon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import default_environment from require "lapis.environment"

colors = require "ansicolors"

unpack = unpack or table.unpack

class Actions
defalt_action: "help"

Expand Down
1 change: 1 addition & 0 deletions lapis/db/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ local is_list
is_list = function(val)
return getmetatable(val) == DBList.__base
end
local unpack = unpack or table.unpack
local is_encodable
is_encodable = function(item)
local _exp_0 = type(item)
Expand Down
2 changes: 2 additions & 0 deletions lapis/db/base.moon
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class DBList
list = (items) -> setmetatable {items}, DBList.__base
is_list = (val) -> getmetatable(val) == DBList.__base

unpack = unpack or table.unpack

-- is item a value we can insert into a query
is_encodable = (item) ->
switch type(item)
Expand Down
5 changes: 3 additions & 2 deletions lapis/db/base_model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ do
local _obj_0 = table
insert, concat = _obj_0.insert, _obj_0.concat
end
local require, type, setmetatable, rawget, assert, pairs, unpack, error, next
local require, type, setmetatable, rawget, assert, pairs, error, next
do
local _obj_0 = _G
require, type, setmetatable, rawget, assert, pairs, unpack, error, next = _obj_0.require, _obj_0.type, _obj_0.setmetatable, _obj_0.rawget, _obj_0.assert, _obj_0.pairs, _obj_0.unpack, _obj_0.error, _obj_0.next
require, type, setmetatable, rawget, assert, pairs, error, next = _obj_0.require, _obj_0.type, _obj_0.setmetatable, _obj_0.rawget, _obj_0.assert, _obj_0.pairs, _obj_0.error, _obj_0.next
end
local unpack = unpack or table.unpack
local cjson = require("cjson")
local add_relations, mark_loaded_relations
do
Expand Down
4 changes: 3 additions & 1 deletion lapis/db/base_model.moon
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import underscore, escape_pattern, uniquify, singularize from require "lapis.util"
import insert, concat from table

import require, type, setmetatable, rawget, assert, pairs, unpack, error, next from _G
import require, type, setmetatable, rawget, assert, pairs, error, next from _G

unpack = unpack or table.unpack

cjson = require "cjson"

Expand Down
1 change: 1 addition & 0 deletions lapis/db/mysql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ do
end
local concat
concat = table.concat
local unpack = unpack or table.unpack
local FALSE, NULL, TRUE, build_helpers, format_date, is_raw, raw, is_list, list, is_encodable
do
local _obj_0 = require("lapis.db.base")
Expand Down
2 changes: 2 additions & 0 deletions lapis/db/mysql.moon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import type, tostring, pairs, select from _G
import concat from table

unpack = unpack or table.unpack

import
FALSE
NULL
Expand Down
1 change: 1 addition & 0 deletions lapis/db/mysql/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local concat
concat = table.concat
local gen_index_name
gen_index_name = require("lapis.db.base").gen_index_name
local unpack = unpack or table.unpack
local append_all
append_all = function(t, ...)
for i = 1, select("#", ...) do
Expand Down
2 changes: 2 additions & 0 deletions lapis/db/mysql/schema.moon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import escape_literal, escape_identifier from db
import concat from table
import gen_index_name from require "lapis.db.base"

unpack = unpack or table.unpack

append_all = (t, ...) ->
for i=1, select "#", ...
t[#t + 1] = select i, ...
Expand Down
1 change: 1 addition & 0 deletions lapis/db/pagination.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ do
end
local get_fields
get_fields = require("lapis.util").get_fields
local unpack = unpack or table.unpack
local query_parts = {
"where",
"group",
Expand Down
2 changes: 2 additions & 0 deletions lapis/db/pagination.moon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import insert, concat from table
import get_fields from require "lapis.util"

unpack = unpack or table.unpack

query_parts = {"where", "group", "having", "order", "limit", "offset"}
rebuild_query_clause = (parsed) ->
buffer = {}
Expand Down
1 change: 1 addition & 0 deletions lapis/db/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ do
local _obj_0 = _G
type, tostring, pairs, select = _obj_0.type, _obj_0.tostring, _obj_0.pairs, _obj_0.select
end
local unpack = unpack or table.unpack
local raw_query, raw_disconnect
local logger
local FALSE, NULL, TRUE, build_helpers, format_date, is_raw, raw, is_list, list, is_encodable
Expand Down
1 change: 1 addition & 0 deletions lapis/db/postgres.moon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import concat from table
import type, tostring, pairs, select from _G
unpack = unpack or table.unpack

local raw_query, raw_disconnect
local logger
Expand Down
5 changes: 3 additions & 2 deletions lapis/db/postgres/model.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local db = require("lapis.db.postgres")
local select, pairs, unpack, type
local select, pairs, type
do
local _obj_0 = _G
select, pairs, unpack, type, select = _obj_0.select, _obj_0.pairs, _obj_0.unpack, _obj_0.type, _obj_0.select
select, pairs, type, select = _obj_0.select, _obj_0.pairs, _obj_0.type, _obj_0.select
end
local unpack = unpack or table.unpack
local insert
insert = table.insert
local BaseModel, Enum, enum
Expand Down
3 changes: 2 additions & 1 deletion lapis/db/postgres/model.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
db = require "lapis.db.postgres"

import select, pairs, unpack, type, select from _G
import select, pairs, type, select from _G
unpack = unpack or table.unpack
import insert from table

import BaseModel, Enum, enum from require "lapis.db.base_model"
Expand Down
1 change: 1 addition & 0 deletions lapis/db/postgres/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local escape_literal, escape_identifier, is_raw
escape_literal, escape_identifier, is_raw = db.escape_literal, db.escape_identifier, db.is_raw
local concat
concat = table.concat
local unpack = unpack or table.unpack
local append_all
append_all = function(t, ...)
for i = 1, select("#", ...) do
Expand Down
1 change: 1 addition & 0 deletions lapis/db/postgres/schema.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ db = require "lapis.db.postgres"
import gen_index_name from require "lapis.db.base"
import escape_literal, escape_identifier, is_raw from db
import concat from table
unpack = unpack or table.unpack

append_all = (t, ...) ->
for i=1, select "#", ...
Expand Down
7 changes: 5 additions & 2 deletions lapis/html.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ do
local _obj_0 = table
concat, insert = _obj_0.concat, _obj_0.insert
end
local _G = _G
local type, pairs, ipairs, tostring, getmetatable, setmetatable, table
type, pairs, ipairs, tostring, getmetatable, setmetatable, table = _G.type, _G.pairs, _G.ipairs, _G.tostring, _G.getmetatable, _G.setmetatable, _G.table
do
local _obj_0 = _G
type, pairs, ipairs, tostring, getmetatable, setmetatable, table = _obj_0.type, _obj_0.pairs, _obj_0.ipairs, _obj_0.tostring, _obj_0.getmetatable, _obj_0.setmetatable, _obj_0.table
end
local unpack = unpack or table.unpack
local getfenv, setfenv
do
local _obj_0 = require("lapis.util.fenv")
Expand Down
3 changes: 2 additions & 1 deletion lapis/html.moon
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

import concat, insert from table

_G = _G
import type, pairs, ipairs, tostring, getmetatable,
setmetatable, table from _G

unpack = unpack or table.unpack

import getfenv, setfenv from require "lapis.util.fenv"

import locked_fn, release_fn from require "lapis.util.functions"
Expand Down
1 change: 1 addition & 0 deletions lapis/nginx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ end
local run_after_dispatch
run_after_dispatch = require("lapis.nginx.context").run_after_dispatch
local lapis_config = require("lapis.config")
local unpack = unpack or table.unpack
local flatten_params
flatten_params = function(t)
local _tbl_0 = { }
Expand Down
2 changes: 2 additions & 0 deletions lapis/nginx.moon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import escape_pattern, parse_content_disposition, build_url from require "lapis.
import run_after_dispatch from require "lapis.nginx.context"
lapis_config = require "lapis.config"

unpack = unpack or table.unpack

flatten_params = (t) ->
{k, type(v) == "table" and v[#v] or v for k,v in pairs t}

Expand Down
1 change: 1 addition & 0 deletions lapis/nginx/cache.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local json = require("cjson")
local unpack = unpack or table.unpack
local sort, concat
do
local _obj_0 = table
Expand Down
2 changes: 2 additions & 0 deletions lapis/nginx/cache.moon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

json = require "cjson"

unpack = unpack or table.unpack

import sort, concat from table

default_dict_name = "page_cache"
Expand Down
1 change: 1 addition & 0 deletions lapis/router.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local insert
insert = table.insert
local unpack = unpack or table.unpack
local lpeg = require("lpeg")
local R, S, V, P
R, S, V, P = lpeg.R, lpeg.S, lpeg.V, lpeg.P
Expand Down
1 change: 1 addition & 0 deletions lapis/router.moon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-- :something[num] *[slug]

import insert from table
unpack = unpack or table.unpack

lpeg = require "lpeg"

Expand Down
1 change: 1 addition & 0 deletions lapis/spec/db.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local assert_env
assert_env = require("lapis.environment").assert_env
local unpack = unpack or table.unpack
local truncate_tables
truncate_tables = function(...)
local db = require("lapis.db")
Expand Down
2 changes: 2 additions & 0 deletions lapis/spec/db.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import assert_env from require "lapis.environment"

unpack = unpack or table.unpack

truncate_tables = (...) ->
db = require "lapis.db"

Expand Down
1 change: 1 addition & 0 deletions lapis/spec/request.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local env = require("lapis.environment")
local unpack = unpack or table.unpack
local normalize_headers
do
local normalize
Expand Down
2 changes: 2 additions & 0 deletions lapis/spec/request.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

env = require "lapis.environment"

unpack = unpack or table.unpack

normalize_headers = do
normalize = (header) ->
header\lower!\gsub "-", "_"
Expand Down
1 change: 1 addition & 0 deletions lapis/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ do
local _obj_0 = table
concat, insert = _obj_0.concat, _obj_0.insert
end
local unpack = unpack or table.unpack
local floor
floor = math.floor
local date
Expand Down
1 change: 1 addition & 0 deletions lapis/util.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ url = require "socket.url"
json = require "cjson"

import concat, insert from table
unpack = unpack or table.unpack
import floor from math

-- TODO: make this a dependency
Expand Down
1 change: 1 addition & 0 deletions lapis/validate.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local insert
insert = table.insert
local unpack = unpack or table.unpack
local validate_functions = {
exists = function(input)
return input and input ~= "", "%s must be provided"
Expand Down
2 changes: 2 additions & 0 deletions lapis/validate.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import insert from table

unpack = unpack or table.unpack

validate_functions = {
exists: (input) ->
input and input != "", "%s must be provided"
Expand Down
2 changes: 2 additions & 0 deletions spec/core_model_specs.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

assert = require "luassert"

unpack = unpack or table.unpack

assert_same_rows = (a, b) ->
a = {k,v for k,v in pairs a}
b = {k,v for k,v in pairs b}
Expand Down
2 changes: 2 additions & 0 deletions spec/mysql_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "spec.helpers" -- for one_of
db = require "lapis.db.mysql"
schema = require "lapis.db.mysql.schema"

unpack = unpack or table.unpack

-- TODO: we can't test escape_literal with strings here because we need a
-- connection for escape function

Expand Down
2 changes: 2 additions & 0 deletions spec/postgres_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "spec.helpers" -- for one_of
db = require "lapis.db.postgres"
schema = require "lapis.db.postgres.schema"

unpack = unpack or table.unpack

value_table = { hello: "world", age: 34 }

tests = {
Expand Down
2 changes: 2 additions & 0 deletions spec/routes_spec.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import Router, RouteParser from require "lapis.router"

unpack = unpack or table.unpack

build_router = (routes) ->
handler = (...) -> { ... }
with r = Router!
Expand Down
2 changes: 2 additions & 0 deletions spec/util_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
util = require "lapis.util"
json = require "cjson"

unpack = unpack or table.unpack

tests = {
{
-> util.parse_query_string "field1=value1&field2=value2&field3=value3"
Expand Down
2 changes: 2 additions & 0 deletions spec_postgres/model_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import setup_db, teardown_db from require "spec_postgres.helpers"

import drop_tables, truncate_tables from require "lapis.spec.db"

unpack = unpack or table.unpack

db = require "lapis.db.postgres"
import Model, enum from require "lapis.db.postgres.model"
import types, create_table from require "lapis.db.postgres.schema"
Expand Down

0 comments on commit d3a16d1

Please sign in to comment.