geqintan commited on
Commit
8967145
·
1 Parent(s): 1dab5c6
Files changed (2) hide show
  1. app.lua +13 -0
  2. app/v1/app.lua +16 -5
app.lua CHANGED
@@ -30,4 +30,17 @@ ngx.say("pass_url: ", pass_url)
30
  local lua_path = "app/" ..api_version .. "/app"
31
  ngx.say("lua_path: ", lua_path)
32
  module = require("app/" .. api_version .. "/app") --require 是没问题的
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ngx.say("module.a: ", module.a)
 
30
  local lua_path = "app/" ..api_version .. "/app"
31
  ngx.say("lua_path: ", lua_path)
32
  module = require("app/" .. api_version .. "/app") --require 是没问题的
33
+
34
+
35
+ -- 检查模块是否加载成功
36
+ if type(module) ~= "table" then
37
+ ngx.say("Error: Failed to load module")
38
+ ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
39
+ end
40
+
41
+ -- 调用模块中的函数
42
+ module.some_function() -- 调用 some_function
43
+ module.another_function() -- 调用 another_function
44
+
45
+
46
  ngx.say("module.a: ", module.a)
app/v1/app.lua CHANGED
@@ -1,6 +1,17 @@
1
  ngx.say("version: v1")
2
- local module = {
3
- a = "some_value",
4
- b = "another_value"
5
- }
6
- return module
 
 
 
 
 
 
 
 
 
 
 
 
1
  ngx.say("version: v1")
2
+ -- 定义一个模块表
3
+ local app_module = {}
4
+
5
+ app_module.a="a in app_v1.lua"
6
+ -- 定义一个函数
7
+ function app_module.some_function()
8
+ ngx.say("This is some_function from app/v1/app.lua")
9
+ end
10
+
11
+ -- 定义另一个函数
12
+ function app_module.another_function()
13
+ ngx.say("This is another_function from app/v1/app.lua")
14
+ end
15
+
16
+ -- 返回模块表
17
+ return app_module