Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 482

Calling table-based functions via inline Lua: not possible? (namespaces, etc)

$
0
0
Something I was planning on doing with a collection of skins was creating separate pseudo namespaces for imported script functions, since anything imported via `dofile()` will be combined with the current script functions, which restricts function names to ones which won't conflict with others that have been imported. I have many scripts that get used in different combinations so it would be cleaner

This is possible by making a table in the script to be imported, like `local foo = {}`, then adding functions to the table like `foo.someFunc = function(arg)`, then returning the table at the end of the file. While in the parent script importing it with a custom pseudo namespace using `imFunc = dofile(...)`, to be used like `imFunc.someFunc()`.

However in just a simple test of calling such table functions via inline Lua, separate than any dofile imports, it seems Rainmeter doesn't handle table based function names for inline Lua, with an error about 'Not a valid function name'.

I know table keys can't be used directly for inline Lua arguments via INI but I suppose this also extends to the function names themselves?

Example skin:

Code:

[Rainmeter]Update=1000DynamicWindowSize=1[String]Meter=StringW=200H=50FontFace=Segoe UIFontSize=11FontColor=255,255,255,255Text=[&S:Foo.Txt('Hello')]SolidColor=0,0,0,255AntiAlias=1ClipString=1DynamicVariables=1[S]Measure=ScriptScriptFile=Script.luaUpdateDivider=-1
Example script:

Code:

Foo = {}Foo.Txt = function(str)    return strend

Miscellaneous notes:

- The alternative table function syntax of `function Foo.Txt(arg)` fails similarly.

Statistics: Posted by Crest — Yesterday, 1:12 pm — Replies 2 — Views 90



Viewing all articles
Browse latest Browse all 482

Trending Articles