开发者

How could i do a configuration system for my Lua extensions?

开发者 https://www.devze.com 2023-03-10 08:39 出处:网络
I added lua scripting support for my C software to allow for easier extension and addition of new features.

I added lua scripting support for my C software to allow for easier extension and addition of new features.

For example, I look for .lua files inside a folder. Those plugins contain functions to identify to my software, like:

functi开发者_如何学JAVAon GetName()
    return "Youtube Search"
end

It have too the "Workers functions" for example:

function Search(strTerm, SearchResult)
     --SEACH YOUTUBE
     SearchResult = MYRESULTS    
end

This way, my software now can search on youtube thanks to this plugin.

But now I have a problem, I cannot find a suitable solution to it. Some plugins require a configuration system, for example in this Youtube plugin it needs a property that only return WebM videos. But a liveLeak plugin don´t need this property.

In the my Application it should be capable of parsing what the plugin need (2 integers and 1 string) and then displaying it in a list.

How could I elegantly implement a solution that fix those issues?


How about a pair of functions (optionally) exposed by plugins like getSupportedConfigItems() and setConfigItems(tbl)? If I'm understanding your question correctly (and I must admit, the "2 integers and 1 string" part I do not understand), it could look like this for the YouTube plugin:

function getSupportedConfigItems()
    return {
        showWebMOnly = {
            type = 'boolean',
            description = 'Show only WebM videos',
            default = true
        }
    }
end

function setConfigItems(tbl)
    for key, value in pairs(tbl) do
        if key == 'showWebMOnly' then
            -- ...
        end
    end
end

This way your application could be written to support showing preferences for a few well-known types (defined by you, the example being a boolean). The application would ask each plugin what preferences it can support, and display options for those. It would then tell the plugin which options were selected, and what their values are.

0

精彩评论

暂无评论...
验证码 换一张
取 消