Include problems

Is there any way to include lua files that are in a directory outside of the one that you’re including from? I’m trying to do something like this:

lua/autorun/file.lua -- This would include the below
lua/customfolder/folder/file.lua -- This doesn't get included. :(

Using “…/” didn’t work. Ideas?

It probably doesn’t let you.

Are there any alternatives?

If it’s being restricted, I doubt it. But I’m not positive.

I have tried doing the exact same thing, and a solution would be very much appreciated.

If garry is blocking it, I can’t help but wonder why. Is there some way it could be violently exploited?

If I were you grease. I’d ask Azuisleet, or even Garry. But I’d ask Azui as he is probably more likely to respond quicker.




He meant within autorun/file.lua, it would include customfolder/folder/file.lua.

For a minute there I actually thought he blocked it. Do what jason2010 said. If the file could not be found in the autorun folder, it will try to search for it in the root lua folder.

try using // instead of / in the filename
worked for me :3

I’m pretty sure it will say “File could not be found”.

You should be able to. Make sure that you’re not going outside of the Lua directory though… From what I remember, include(…) will always be relative to the Lua directory.


Whoops. If the file is not found in the directory you’re trying to include from, it will search for it in the root directory. I’m sure it has always worked like that.

What jason2010 said worked… surprisingly. I tried so many different things and none of them worked. I got ‘Lua GetFile’ errors for using …/ and such.

Now, will this work from inside an addon? Say for instance, include something from the real lua folder?

Addon folders are essentially merged with the main folder. Doing something in addons/blah/lua/bla/ is the same as doing it in garrysmod/lua/bla. You can’t, however, include something from a specific addon - including garrysmod/addons/blah/lua/blah/blah.lua from lua/autorun/blah.lua will not work.

I meant the other way around: A file in an addon including a file from the root lua folder.


It appears to work. :buddy: