openresty not see required lua files in the subdir

383 views
Skip to first unread message

Yuriy Gorlichenko

unread,
Jun 5, 2017, 1:14:09 PM6/5/17
to openresty-en
Lets  say i have this map of project:

html
      |- dir
          |- file1.lua
          |- file2.lua

If I writing in file1.lua

f2 = require "file2"

I lave fail down code parser with

 /usr/local/openresty/nginx/html/dir/file1.lua:1: module 'file2' not found:
        no field package.preload['file2']
        no file '/usr/local/share/lua/5.1/file2.lua'
        no file '/usr/local/openresty/lualib/file2.lua'
        no file '/usr/local/openresty/nginx/html/file2.lua'
        no file '/usr/local/openresty/site/lualib/file2.so'
        no file '/usr/local/openresty/lualib/file2.so'
        no file './file2.so'
        no file '/usr/local/lib/lua/5.1/file2.so'
        no file '/usr/local/openresty/luajit/lib/lua/5.1/file2.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

If i do same thing with console luaJIT i see that all ok and if I will delete file2.lua i watch next:

/usr/local/openresty/luajit/bin/luajit:  file1.lua:1: module 'file2' not found:
        no field package.preload['file2']
        no file './file2.lua'
        no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/file2.lua'
        no file '/usr/local/share/lua/5.1/file2.lua'
        no file '/usr/local/share/lua/5.1/file2/init.lua'
        no file '/usr/local/openresty/luajit/share/lua/5.1/file2.lua'
        no file '/usr/local/openresty/luajit/share/lua/5.1/file2/init.lua'
        no file './file2.so'
        no file '/usr/local/lib/lua/5.1/file2.so'
        no file '/usr/local/openresty/luajit/lib/lua/5.1/file2.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

Difference between 1 and 2 output that first output have no:
       no file './file2.lua' 
string

As i understand openresty not trying to find any lua file in subdirs. It maps only from "html" dir because if i rewrite require like

local file2 = require  "dir.file2" it works fine

Yuriy Gorlichenko

unread,
Jun 5, 2017, 1:40:28 PM6/5/17
to openresty-en
Also I added to my lua_package_path '/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/nginx/html/?.lua;;'

And output now with ./file2.lua but still not found but it exists in the dir.

понедельник, 5 июня 2017 г., 20:14:09 UTC+3 пользователь Yuriy Gorlichenko написал:

FQ Liu

unread,
Jun 6, 2017, 2:34:27 AM6/6/17
to openresty-en
f2 =require "dir.file2"

use dot like this

在 2017年6月6日星期二 UTC+8上午1:40:28,Yuriy Gorlichenko写道:

Yuriy Gorlichenko

unread,
Jun 6, 2017, 5:04:59 AM6/6/17
to openre...@googlegroups.com
Yes couse main idea to include file2 in the same dir where file1exists. mean not from resty's root dir.


вторник, 6 июня 2017 г. пользователь FQ Liu написал:
--
You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/0_vjxBYu_u4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openresty-en+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eduardo Berbis

unread,
Jun 6, 2017, 5:10:48 AM6/6/17
to openre...@googlegroups.com
What about updating your `lua_package_path` to:

lua_package_path "/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/nginx/html/dir/?.lua;;";

?

That way I think you shouldn't have problems accessing it via:

f2 = require "file2"

I normally have all my `lua` files within a folder called `lua` itself, so my `lua_package_path` looks like this:

lua_package_path "${prefix}lua/?.lua;;";

Hope that helps


--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages