RoStrap / Resources

RoStrap's Core Bootstrapper

Home Page:https://rostrap.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restructuring the LoadLibrary command

devSparkle opened this issue · comments

The LoadLibrary command is an essential part of the Nevermore framework. It allows for developers to organize and structure their code in conveniently named modules. It allow for the segmentation of code, ease of maintenance of each individual module and pushes for worthwhile coding standards.

Seeing as this function is core to what we do, it's clear that we should re-assess its goals and overall functionality. I therefor propose the following standard is adopted for V2:

void LoadLibrary (
    string LibraryName
    bool IgnoreIfNil = false
)

As you can see, the first argument remains the same, allowing for backwards compatibility with prior versions of the framework. However, the new, optional second argument opens up a wide range of options for developers. I propose that this second argument would allow a developer to declare a module as optional, such that any calls to the module would be ignored should it not be present.

A good use case example for this would be an analytics module. If this module is not present, no action would be taken. However, if this module is present it would collect statistics using functionality built in by the module developer.

"No action would be taken"

So basically, it would not error, and not run the module, but what if parts of the module refer to the missing library?

How would we know how to deal with functions called on this non-existent module? How would we deal with whether a number was returned, a function, a string, a boolean? There is no way to deal with this.

Nevermore:LoadLibrary("LibraryName", true):Run()

I don't think there is any way to address this on the Nevermore side.

I think what you are looking for is pcall

@Narrev we could certainly use metatables to have every module call return nil?

Certainly, but all that is not necessary because we can just use pcall. The point of Nevermore (or whatever it will be called soon enough) is to always get the resource you are looking for. I don't want to implement something contrary to that idea, which is just a glorified pcall, just so you don't have to put pcall in your module.

If you want to implement this idea in an individual module, go for it. However, I just don't think it should be built-in to Nevermore.

local Success, GoogleReporter = pcall(LoadLibrary, "GoogleReporter")
if not Success then
    GoogleReporter = setmetatable({}, {
        __index = function(i)
            local function v() end
            self[i] = v
            return v
        end
    })
end

Please close the issue if you agree.

I agree with Narrev here. You generally want errors to fail loudly.

Nevermore is not designed to dynamically load (and more importantly: unload) modules on the fly.