From 0061cca2e76b22d0c39b035a30b04d59563ecee5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 30 Mar 2024 21:15:09 +0000 Subject: is_required and testcase --- is_required.lua | 16 ++++++++++++++++ test.dat | 1 + test.lua | 21 ++------------------- 3 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 is_required.lua create mode 100644 test.dat 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()) -- cgit v1.2.3