Lua-Plugins erstellen
Verfasst: Donnerstag 16. Januar 2014, 12:23
@seife
kannst du einen lua demo plugins bitte zu Verfügung stellen?
thx
kannst du einen lua demo plugins bitte zu Verfügung stellen?
thx
Code: Alles auswählen
-- print goes to stdout
print("hallo lua")
print(RC['RC_home'])
SX = SCREEN['OFF_X']
SY = SCREEN['OFF_Y']
EX = SCREEN['END_X']
EY = SCREEN['END_Y']
print("SX:" .. SX .. " SY:" .. SY .. " EX:" .. EX .. " EY:" .. EY)
local n = neutrino() -- max size
sx = SCREEN['OFF_X'] + 20
sy = SCREEN['OFF_Y'] + 20
w = SCREEN['END_X'] - 20 - sx
h = SCREEN['END_Y'] - 20 - sy
f = FONT['CHANNELLIST']
n:PaintBox(sx, sy, w, h, COL['MENUCONTENT'] + 0)
n:RenderString(f, "Hallo Lua!", 100, 100, COL['MENUCONTENT_TEXT'])
msg, data = n:GetInput(1000) -- sleep(1)
-- n = nil -- funktioniert nicht, ein "destruktor" fehlt noch
sx = SCREEN['OFF_X'] + 100
sy = SCREEN['OFF_Y'] + 100
w = SCREEN['END_X'] - 100 - sx
h = SCREEN['END_Y'] - 100 - sy
local m = neutrino(sx, sy, w, h);
m:PaintBox(-1, -1, -1, -1, COL['MENUCONTENT'] + 1) -- max size
m:RenderString(f, "Hallo Lua2!", 100, 100, COL['MENUCONTENT_TEXT'])
repeat
msg, data = m:GetInput(1000)
print("msg: " .. msg .. " data: " .. data)
until msg == RC['home']
neutrino():RenderString(f, "1 to exit", 200, 400, COL['MENUCONTENT_TEXT'])
repeat
msg, data = m:GetInput(1000)
print("msg: " .. msg .. " data: " .. data)
until msg == RC['1']
print("ciao!")
--end
Code: Alles auswählen
name=Lua Test
desc=tests lua
type=4
needfb=1
needrc=1
needoffsets=1
Code: Alles auswählen
listbox = {}
listbox.header = "Header Text"
listbox.entries = {
"First entry",
"second entry",
"third!",
"four",
"fünf",
"six",
"seven",
"888888888888"
}
-- global setting for rounded corners
radius = CORNER.RADIUS_MID
round_top = bit32.bor(CORNER.TOP_LEFT, CORNER.TOP_RIGHT)
round_bottom = bit32.bor(CORNER.BOTTOM_LEFT, CORNER.BOTTOM_RIGHT)
round_all = bit32.bor(round_top, round_bottom)
--
-- first call without position to initialize values
--
listbox.paint = function(self, sel)
if sel == nil then -- initialize
self.xs = self.x+10 -- string start
self.ws = self.w-20 -- string end
self.h_font = FONT.MENU_TITLE
self.b_font = FONT.MENU
self.b_height = n:FontHeight(self.b_font)
if self.header then
self.h_height = n:FontHeight(self.h_font)
n:PaintBox(self.x, self.y, self.w, self.h_height, COL.MENUHEAD, radius, round_top)
n:RenderString(self.h_font, self.header, self.xs, self.y + self.h_height, COL.MENUHEAD_TEXT, self.ws)
else
self.h_height = 0
end
self.offset = 1 -- start with first item
local avail = self.h - self.h_height
self.cap = math.floor(avail / self.b_height)
else
while sel - self.offset >= self.cap do
self.offset = self.offset + self.cap
self.old = nil -- "page change"
end
while sel < self.offset do
self.offset = self.offset - self.cap
self.old = nil
end
end
if self.old == nil then -- initial call or changed page
local round = self.h_height == 0 and round_all or round_bottom
n:PaintBox(self.x, self.y + self.h_height, self.w, self.h - self.h_height, COL.MENUCONTENT, radius, round)
end
local yy = self.y + self.h_height + self.b_height
for idx,entry in pairs(self.entries) do
if idx >= self.offset and yy <= self.y + self.h then
if self.old == nil then
n:RenderString(self.b_font, entry, self.xs, yy, COL.MENUCONTENT_TEXT, self.ws)
end
if self.old ~= sel then -- selection changed
local col, colt
if idx == self.old then
col = COL.MENUCONTENT
colt = COL.MENUCONTENT_TEXT
elseif idx == sel then
col = COL.MENUCONTENTSELECTED
colt = COL.MENUCONTENTSELECTED_TEXT
end
if col then
n:PaintBox(self.x, yy - self.b_height, self.w, self.b_height, col, radius)
n:RenderString(self.b_font, entry, self.xs, yy, colt, self.ws)
end
end
yy = yy+self.b_height
end
end
self.old = sel
end
--
-- main()
--
SX = SCREEN.OFF_X
SY = SCREEN.OFF_Y
EX = SCREEN.END_X
EY = SCREEN.END_Y
print("SX:"..SX.." SY:"..SY.." EX:"..EX.." EY:"..EY)
n = neutrino() -- max size
-- set dimensions of the listbox
listbox.x = SX+50
listbox.y = SY+50
listbox.w = EX-100
listbox.h = 5 * n:FontHeight(FONT.MENU) -- small, to force scrolling
listbox.paint(listbox)
i = 1
repeat
listbox.paint(listbox, i)
msg, data = n:GetInput(1000) -- sleep(1)
if msg == RC.up then
i = i - 1
if i < 1 then i = #listbox.entries end
elseif msg == RC.down then
i = i + 1
if i > #listbox.entries then i = 1 end
end
print("msg: "..msg.." data: "..data.." i: "..i)
until msg == RC.home
print("bye")
Code: Alles auswählen
name=Lua Window
desc=window
type=4
needfb=1
needrc=1
needoffsets=1
Code: Alles auswählen
listbox.entries = {
{ name = "Börse", exec = "boerse.sh"},
{ name = "Handball", exec= "'handhall.sh options'"}
}
Code: Alles auswählen
listbox = {}
listbox.header = "Flex Nachbau"
listbox.entries = {
"Börse",
"Handball",
}
listbox.executes = {
"/share/tuxbox/neutrino/plugins/boerse.sh",
"/share/tuxbox/neutrino/plugins/handball.sh",
}
-- global setting for rounded corners
radius = CORNER.RADIUS_MID
round_top = bit32.bor(CORNER.TOP_LEFT, CORNER.TOP_RIGHT)
round_bottom = bit32.bor(CORNER.BOTTOM_LEFT, CORNER.BOTTOM_RIGHT)
round_all = bit32.bor(round_top, round_bottom)
--
-- first call without position to initialize values
--
listbox.paint = function(self, sel)
if sel == nil then -- initialize
self.xs = self.x+10 -- string start
self.ws = self.w-20 -- string end
self.h_font = FONT.MENU_TITLE
self.h_height = n:FontHeight(self.h_font)
self.b_font = FONT.MENU
self.b_height = n:FontHeight(self.b_font)
-- calc window h and y -- FIXME
self.h = self.h_height + (#listbox.entries * self.b_height)
self.y = ((EY - SY) /2) - (self.h / 2)
if self.header then
n:PaintBox(self.x, self.y, self.w, self.h_height, COL.MENUHEAD, radius, round_top)
n:RenderString(self.h_font, self.header, self.xs, self.y + self.h_height, COL.MENUHEAD_TEXT, self.ws)
else
self.h_height = 0
end
self.offset = 1 -- start with first item
local avail = self.h - self.h_height
self.cap = math.floor(avail / self.b_height)
else
while sel - self.offset >= self.cap do
self.offset = self.offset + self.cap
self.old = nil -- "page change"
end
while sel < self.offset do
self.offset = self.offset - self.cap
self.old = nil
end
end
if self.old == nil then -- initial call or changed page
local round = self.h_height == 0 and round_all or round_bottom
n:PaintBox(self.x, self.y + self.h_height, self.w, self.h - self.h_height, COL.MENUCONTENT, radius, round)
end
local yy = self.y + self.h_height + self.b_height
for idx, entry in pairs(self.entries) do
if idx >= self.offset and yy <= self.y + self.h then
if self.old == nil then
n:RenderString(self.b_font, entry, self.xs, yy, COL.MENUCONTENT_TEXT, self.ws)
end
if self.old ~= sel then -- selection changed
local col, colt
if idx == self.old then
col = COL.MENUCONTENT
colt = COL.MENUCONTENT_TEXT
elseif idx == sel then
col = COL.MENUCONTENTSELECTED
colt = COL.MENUCONTENTSELECTED_TEXT
end
if col then
n:PaintBox(self.x, yy - self.b_height, self.w, self.b_height, col, radius)
n:RenderString(self.b_font, entry, self.xs, yy, colt, self.ws)
end
end
yy = yy+self.b_height
end
end
self.old = sel
end
--
-- main()
--
SX = SCREEN.OFF_X
SY = SCREEN.OFF_Y
EX = SCREEN.END_X
EY = SCREEN.END_Y
print("SX:"..SX.." SY:"..SY.." EX:"..EX.." EY:"..EY)
n = neutrino() -- max size
-- set dimensions of the listbox
listbox.w = (EX-SX) / 2
listbox.h = nil -- (EY-SY) / 2
listbox.x = SX + (listbox.w / 2)
listbox.y = nil -- SY + (listbox.h / 2)
listbox.paint(listbox)
i = 1
repeat
listbox.paint(listbox, i)
msg, data = n:GetInput(1000) -- sleep(1)
if msg == RC.up then
i = i - 1
if i < 1 then i = #listbox.entries end
elseif msg == RC.down then
i = i + 1
if i > #listbox.entries then i = 1 end
end
if msg == RC.ok then
print("key OK, i: " ..i.. " execute: " ..listbox.executes[i])
os.execute(listbox.executes[i])
end
print("msg: "..msg.." data: "..data.." i: "..i)
until msg == RC.home
print("bye")
Code: Alles auswählen
listbox.entries = {
{ name = "Börse", exec = "/share/tuxbox/neutrino/plugins/boerse.sh"},
{ name = "Handball", exec = "/share/tuxbox/neutrino/plugins/handhall.sh"}
}
names = {}
execs = {}
for v, w in ipairs(listbox.entries) do
names[v] = w.name
execs[v] = w.exec
end
... und sogar Funktionen und Methoden.Und natürlich kann man alles in eine Tabelle reinpacken, auch andere Tabellen
Code: Alles auswählen
#!/bin/lua
n = neutrino()
h = hintbox.new{caption="Header", text="Content"}
h:paint()
repeat
msg, data = n:GetInput(500)
until msg == RC.ok or msg == RC.home
h:hide()
Code: Alles auswählen
# cat /lib/tuxbox/luaplugins/test.lua
for i,v in ipairs(arg) do
print(tostring(i) .. "\t" .. tostring(v))
end
return "ok"
# luaclient test a b c
da war seife wo anders (libtuxtxt) schneller, da nhttpd nicht als standalone Deamon läuft eigene RC -Event Code im nhttpd hat kein Sinn mir man koennte das wie im seifes tuxtxt machen (im Neutrino-HD2 ist langher shamelos aus siefes tuxtxt geklaut ) der neutrino RCInput pointer nutzen und somit solange man den Plugin ausführt gehen die event nicht an nhttpd oder auch immer wasmartii hat geschrieben:# der Plugin-Aufruf nur möglich sein darf, wenn Neutrino nicht zeitgleich versucht, die RC-Events abzugreifen
Code: Alles auswählen
name=Lua Test
desc=tests lua
type=4
needfb=1
needrc=1
needoffsets=1
Code: Alles auswählen
new_plugin.pluginfile = fname;
if (new_plugin.type == CPlugins::P_TYPE_SCRIPT)
new_plugin.pluginfile.append(".sh");
else if (new_plugin.type == CPlugins::P_TYPE_LUA)
new_plugin.pluginfile.append(".lua");
else // CPlugins::P_TYPE_GAME or CPlugins::P_TYPE_TOOL
new_plugin.pluginfile.append(".so");
Code: Alles auswählen
typedef enum plugin_type
{
PLUGIN_TYPE_DISABLED = 0,
PLUGIN_TYPE_GAME = 1,
PLUGIN_TYPE_TOOL = 2,
PLUGIN_TYPE_SCRIPT = 3,
PLUGIN_TYPE_LUA = 4
}
plugin_type_t;
OK. Das lässt sich sicher reparieren. Ebenso sicher hat das aber nichts mit der internen Handhabung der Plugin-Typen zu tun.schufti hat geschrieben:Naja, ich hatte damit zu kämpfen, dass Hinticons nicht angezeigt werden, wenn das Plugin auf "disabled" gesetzt ist (also nicht per "Liste" eingebunden werden soll) aber direkt im Usermenü plaziert ist.