1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

An object-oriented api for accessing data sources from lua

This commit is contained in:
Pavel Labath 2010-02-13 17:00:20 +01:00
parent b3411782e6
commit fa02cdceab
2 changed files with 16 additions and 0 deletions

View File

@ -4323,6 +4323,8 @@ int main(int argc, char **argv)
"print(conky.asnumber(conky.variables.asdf{}));\n"
"print(conky.astext(conky.variables.asdf{}));\n"
"print(conky.asnumber(conky.variables.zxcv{}));\n"
"print(conky.variables.asdf{}.text);\n"
"print(conky.variables.asdf{}.xxx);\n"
);
l.call(0, 0);
}

View File

@ -64,6 +64,17 @@ namespace conky {
l->setmetatable(-2);
return 1;
}
const char data_source__index[] =
"local table, key = ...;\n"
"if key == 'num' then\n"
" return conky.asnumber(table);\n"
"elseif key == 'text' then\n"
" return conky.astext(table);\n"
"else\n"
" print(string.format([[Invalid data source operation: '%s']], key));\n"
" return 0/0;\n"
"end\n";
}
void export_symbols(lua::state &l)
@ -77,6 +88,9 @@ namespace conky {
l.pushdestructor<std::shared_ptr<data_source_base>>(); ++s;
l.rawsetfield(-2, "__gc"); --s;
l.loadstring(data_source__index); ++s;
l.rawsetfield(-2, "__index"); --s;
} l.pop(); --s;
l.newtable(); ++s; {