diff options
author | ubq323 <ubq323@ubq323.website> | 2024-03-30 21:15:09 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-03-30 21:16:33 +0000 |
commit | 0061cca2e76b22d0c39b035a30b04d59563ecee5 (patch) | |
tree | b1c90ea03064a78f45821dfe4e54778ef60fab75 | |
parent | 9f3f88a6ee7b9bd8ab3168d96a81b40e23024cc6 (diff) |
is_required and testcase
-rw-r--r-- | is_required.lua | 16 | ||||
-rw-r--r-- | test.dat | 1 | ||||
-rw-r--r-- | test.lua | 21 |
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 @@ -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()) |