summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-03-30 21:15:09 +0000
committerubq323 <ubq323@ubq323.website>2024-03-30 21:16:33 +0000
commit0061cca2e76b22d0c39b035a30b04d59563ecee5 (patch)
treeb1c90ea03064a78f45821dfe4e54778ef60fab75
parent9f3f88a6ee7b9bd8ab3168d96a81b40e23024cc6 (diff)
is_required and testcase
-rw-r--r--is_required.lua16
-rw-r--r--test.dat1
-rw-r--r--test.lua21
3 files changed, 19 insertions, 19 deletions
diff --git a/is_required.lua b/is_required.lua
new file mode 100644
index 0000000..40b3e88
--- /dev/null
+++ b/is_required.lua
@@ -0,0 +1,16 @@
+local function is_required()
+ local n = 0
+ local res = false
+ while true do
+ local x = debug.getinfo(n)
+ if x == nil then break end
+ n = n + 1
+ if x.name == 'require' then
+ res = true
+
+ break
+ end
+ end
+ return res
+end
+return {is_required = is_required}
diff --git a/test.dat b/test.dat
new file mode 100644
index 0000000..30b5c11
--- /dev/null
+++ b/test.dat
@@ -0,0 +1 @@
+dep is_required
diff --git a/test.lua b/test.lua
index a03f69a..b5878f3 100644
--- a/test.lua
+++ b/test.lua
@@ -1,19 +1,2 @@
-local n = 0
-local is_required = false
-while true do
- local x = debug.getinfo(n)
- if x == nil then break end
- n = n + 1
- if x.name == 'require' then
- is_required = true
-
- break
- end
-end
-
-if is_required then
- print("required")
-else
- print("cmdlined")
-
-end
+local ir = require'is_required'.is_required
+print(ir())