summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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())