I have a situation where I need to use two modules... both of which load / reference another module. So I'm getting an error about a loop.
Here's the code in module1:
require("posix")
posix.setenv("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin")
and in module 2 I have the same thing:
require("posix")
local ts = posix.stat(spath, "ctime")
I found this post: Lua: How to avoid Circular Requires
I tried to apply what the above post said and I changed my logic in both modules to look like this:
posix = posix or require("posix")
But I'm still getting the error message. Any suggestions would be appreciated.
EDIT 1
tester.lua
local main =require("main")
main.lua
module (..., package.seeall)
-- Load libraries
require("commonfunctions")
require("luasql.postgres")
require("session")
commonfunctions.lua
posix = posix or require "posix"
session.lua
posix = posix or require "posix"
Error Message
lua: /usr/share/acf/lib//session.lua:15: loop or previous error loading module 'posix'
stack traceback:
[C]: in function 'require'
/usr/share/lib//session.lua:15: in main chunk
[C]: in function 'require'
/usr/share/myapp/main.lua:10: in main chunk
[C]: in function 'require'
/usr/share/lua/5.1/posix.lua:2: in main chunk
[C]: in function 'require'
/usr/share/acf/lib//commonfunctions.lua:4: in main chunk
[C]: in function 'require'
./kamfmfm-model.lua:3: in main chunk
[C]: in function 'require'
tester.lua:6: in main chunk
[C]: ?