Using Custom Libraries/Modules/Packages

One of the few things I still struggle with in glua is including custom libraries in my addons. I made this thread to discuss best practices. Here are the methods I know of, and the potential issues with them:

I. Put your libraries in a separate addon. I’ve seen a lot of people do this, and it’s more-or-less what I do.

  1. This is technically against the workshop rules.
  2. The average gmod user evidently can’t figure this out.
  3. Annoying to code. Need some kind of bootstrap and probably a way to alert the user if they don’t have the separate addon.

II. Include your libraries in every addon that uses them. CAMI seems to be built with this in mind, and seems to at least try to address some of my concerns.

  1. What happens when you want to update the library? Keeping the library updated in each addon is annoying and would probably need some sort of build script.
  2. What happens when two versions are loaded? This can be fixed pretty easily in code, but it’s still a concern if one addon requires an earlier version.
  3. What about filename conflicts? IIRC, all addons are mounted to a common point, and if two names conflict, only one will be loaded. I know this is an issue with legacy addons and am not sure about workshop addons. I have seen warnings about this in the console before. Again, this can be fixed with code, but it’s fucking annoying to do so and can easily broken by stupid people trying to use your library wrong.

III. Build your own package system using bullshitmagic. Download and cache modules. They could even be downloaded from the workshop, so long as you don’t need any content. I really want to do this but there are a ton of issues with it.

  1. Still requires some kind of core that would probably need to be self-updating somehow.
  2. No synchronous HTTP requests. I know this is generally seen as a good thing, but it can be super annoying when trying to do something like this. You want your module to be loaded synchronously. There are a few solutions to this that I can think of, all of which are super fucking annoying:
  • Wrap your entire addon in a callback. Problems: How are entities/weapons loaded? What if you want to use hooks that are fired early (Init, InitPostEntity, etc) that could be totally skipped? In my experience, HTTP requests are never completed until the first frame.
  • Restart the server/client every time you need to download a library. Problems: This doesn’t suffer from the previous problems, but is such a terrible idea. How many different cases are there? You would have to deal with client/server for singleplayer/listen servers/dedicated… Would be super confusing and time consuming for users, almost loading in and then have the loading reset.
  • Use some co-routine bullshit that would be even more hard to manage than the previous two possibilities.

There are so many corner cases with these that implementing any of them would be a colossal shitshow.

Is there some better way I don’t know about? Something not-shitty hidden in lua’s packaging system? Am I overthinking this? Am I wasting my time bitching about it here? What are your opinions?

IIRC, Arcbank uses a loading system nested in http requests to retrieve its files, and caches them temporarily on server start (when there is a version mismatch) as a table of strings, and if im not mistaken it then uses RunString( string code ) to execute it all.

Could be wrong however. Aritz Cracker is the person who I’ve seen do something like what you are asking.

Last and I just plop all our libs and misc shit in plib. It’s a whole lot better then updating 10 things every change or using some extremely limited http loader.