Hey guys, so I want to divide my Lua code up into multiple
Is it simply that Co-OP DX does not load the
Thanks for reading!
.lua
files without polluting the global namespace. What seems like the best way to do this at least to me is a solution I found on StackOverflow:I've gone and done exactly this, all myWhat you need to do is to return a table with the fields you want to access in subsystem.lua and then assign and use fields from that table in your main file. Something along these lines:
Code:-- subsystem.lua local function doSomething() -- do something useful here end local function doMore() -- do something else useful end return { doSomething = doSomething, doMore = doMore } -- main.lua local subsystem = require "subsystem" -- don't add `.lua` to your `require` call subsystem.doSomething() subsystem.doMore()
.lua
files side-by-side in one directory, and in my IDE this is clearly valid to some degree as going to the definition of methods called outside of the script they are defined in through this require
design finds the definition no problem. The problem comes in when I load my mod folder with all these .lua
scripts in it inside of Co-Op DX, at which point I get multiple exceptions that all read along the lines of:
Code:
attempt to call a nil value (global 'require')
.lua
files in a way that permits this require
design? If so, what are my other options for passing methods and variables around in sibling directory .lua
files without polluting the global namespace? Otherwise, what am I doing wrong here?Thanks for reading!