summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/error.lua36
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/getmetatable.lua32
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/next.lua36
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/pcall.lua36
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/rawequal.lua33
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/rawget.lua34
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/rawset.lua33
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/select.lua36
-rw-r--r--xmake/core/sandbox/modules/import/lib/lua/setmetatable.lua36
9 files changed, 312 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/import/lib/lua/error.lua b/xmake/core/sandbox/modules/import/lib/lua/error.lua
new file mode 100644
index 000000000..4f38f1647
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/error.lua
@@ -0,0 +1,36 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file error.lua
+--
+
+-- the native lua `error`
+--
+-- it is not in the sandbox by default, `raise` is the one to use: it formats the
+-- message and it is what `try`/`catch` understands. `error` is the plain one, for the
+-- code which wants to throw a value rather than a message
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.error")
+--
+-- error("something went wrong")
+-- error({code = 1}) -- a value, not a message
+--
+return error
diff --git a/xmake/core/sandbox/modules/import/lib/lua/getmetatable.lua b/xmake/core/sandbox/modules/import/lib/lua/getmetatable.lua
new file mode 100644
index 000000000..fcef76eb3
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/getmetatable.lua
@@ -0,0 +1,32 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file getmetatable.lua
+--
+
+-- the native lua `getmetatable`
+--
+-- @note the same in lua 5.1 and 5.4, it returns the `__metatable` field when the
+-- metatable is protected
+--
+-- e.g.
+--
+-- import("lib.lua.getmetatable")
+--
+-- local mt = getmetatable(obj)
+--
+return getmetatable
diff --git a/xmake/core/sandbox/modules/import/lib/lua/next.lua b/xmake/core/sandbox/modules/import/lib/lua/next.lua
new file mode 100644
index 000000000..65313dd1a
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/next.lua
@@ -0,0 +1,36 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file next.lua
+--
+
+-- the native lua `next`
+--
+-- it is not in the sandbox by default, `pairs` covers the iteration of a table. `next`
+-- is what is left for the two things `pairs` cannot say: whether a table is empty, and
+-- stepping a traversal by hand
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.next")
+--
+-- if next(tbl) == nil then ... end -- the table is empty
+-- local key, value = next(tbl) -- the first entry, in no particular order
+--
+return next
diff --git a/xmake/core/sandbox/modules/import/lib/lua/pcall.lua b/xmake/core/sandbox/modules/import/lib/lua/pcall.lua
new file mode 100644
index 000000000..1ad150943
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/pcall.lua
@@ -0,0 +1,36 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file pcall.lua
+--
+
+-- the native lua `pcall`
+--
+-- it is not in the sandbox by default, `try`/`catch` is the idiomatic way to handle the
+-- errors of a script, and it keeps the traceback and the error message which xmake
+-- builds. `pcall` is the plain one, for the code which only needs a boolean
+--
+-- @note the same in lua 5.1 and 5.4. `xpcall` is not exported, its message handler
+-- takes the extra arguments only since 5.2
+--
+-- e.g.
+--
+-- import("lib.lua.pcall")
+--
+-- local ok, result = pcall(function () return 1 end)
+--
+return pcall
diff --git a/xmake/core/sandbox/modules/import/lib/lua/rawequal.lua b/xmake/core/sandbox/modules/import/lib/lua/rawequal.lua
new file mode 100644
index 000000000..b9f9ea683
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/rawequal.lua
@@ -0,0 +1,33 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file rawequal.lua
+--
+
+-- the native lua `rawequal`
+--
+-- it compares two values without going through the `__eq` metamethod
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.rawequal")
+--
+-- if rawequal(a, b) then ... end
+--
+return rawequal
diff --git a/xmake/core/sandbox/modules/import/lib/lua/rawget.lua b/xmake/core/sandbox/modules/import/lib/lua/rawget.lua
new file mode 100644
index 000000000..fe5115001
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/rawget.lua
@@ -0,0 +1,34 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file rawget.lua
+--
+
+-- the native lua `rawget`
+--
+-- it reads a field of a table without going through its `__index` metamethod, so it
+-- sees what the table itself holds and not what its metatable would answer
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.rawget")
+--
+-- local value = rawget(tbl, "key")
+--
+return rawget
diff --git a/xmake/core/sandbox/modules/import/lib/lua/rawset.lua b/xmake/core/sandbox/modules/import/lib/lua/rawset.lua
new file mode 100644
index 000000000..917bc3d86
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/rawset.lua
@@ -0,0 +1,33 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file rawset.lua
+--
+
+-- the native lua `rawset`
+--
+-- it writes a field of a table without going through its `__newindex` metamethod
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.rawset")
+--
+-- rawset(tbl, "key", value)
+--
+return rawset
diff --git a/xmake/core/sandbox/modules/import/lib/lua/select.lua b/xmake/core/sandbox/modules/import/lib/lua/select.lua
new file mode 100644
index 000000000..45fb1bbc9
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/select.lua
@@ -0,0 +1,36 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file select.lua
+--
+
+-- the native lua `select`
+--
+-- it is not in the sandbox by default, the scripts of a project rarely need to look at
+-- a raw argument list, but it is the only way to count the arguments of a vararg
+-- function without losing the nils in it
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.select")
+--
+-- local count = select("#", ...) -- how many arguments, nils included
+-- local second = select(2, ...) -- everything from the second one on
+--
+return select
diff --git a/xmake/core/sandbox/modules/import/lib/lua/setmetatable.lua b/xmake/core/sandbox/modules/import/lib/lua/setmetatable.lua
new file mode 100644
index 000000000..6f1d4c330
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/lua/setmetatable.lua
@@ -0,0 +1,36 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file setmetatable.lua
+--
+
+-- the native lua `setmetatable`
+--
+-- it is not in the sandbox by default: a module which builds objects with metatables is
+-- a module which is hard to serialize and to cache, and xmake passes plain tables
+-- around on purpose. it is here for the code which really wants operator overloading or
+-- an `__index` fallback
+--
+-- @note the same in lua 5.1 and 5.4
+--
+-- e.g.
+--
+-- import("lib.lua.setmetatable")
+--
+-- local obj = setmetatable({}, {__index = function (tbl, key) return "?" end})
+--
+return setmetatable