In my current project, I am attempting to add some syntax to my project globally by performing a dofile() at the very top of my main.lua. I am then requiring a third file that uses what I’m attempting to add as a global in my project; however I receive an error attempting to index the global value upon doing so.
For instance, in the example below, I use dofile() in an attempt to make test1:hello() globally available within my project, yet during the process of requiring test2.lua, i receive the error:
PANIC: unprotected error in call to Lua API (test2.lua: attempt to index global 'test1' (a nil value))
Shouldn’t test1 already exist as a global in this case? How can I get around this?
main.lua:
dofile('test1.lua')
require('test2')
test1.lua
test1 = {}
function test1:hello()
print("hello")
end
test2.lua
module('test2')
test1:hello()
in main.lua:
should be:
and in test2.lua i had to pass package.seeall as the second param to module() so that it could see values in test1