i have a router with openwrt 18.06 , in this router i create a new menu for displaying the lte signal, the signal is obtained with a sh script , then in the
/usr/lib/lua/luci/controller/signal-mymodule/signal.lua where i define the menu tree , i add a function to retrieve the data and display it.
all work as excepted
now i wont to rebuild the image with 19.07.3 , and i copy the same file in the new image ... but i have an error
/usr/lib/lua/luci/template.lua:97: Failed to execute template 'signal-mymodule/signal'.
A runtime error occurred: [string "/usr/lib/lua/luci/view/signal-mymodule/sign..."]:1: attempt to call global 'action_test' (a nil value)
[string "/usr/lib/lua/luci/view/signal-mymodule/sign..."]:1: in main chunk
[C]: in function 'error'
/usr/lib/lua/luci/template.lua:97: in function
(tail call): ?
/usr/lib/lua/luci/dispatcher.lua:1020: in function 'dispatch'
/usr/lib/lua/luci/dispatcher.lua:478: in function
it's like if it can't find the function, what i'm missing? (i'm noob in lua programming ....)
i've create a git repo with the file to reproduce the problem, inside the file /usr/lib/lua/luci/view/view-mymodule/view_file.htm i recall the function action_test() that is declared int the file /usr/lib/lua/luci/controller/test/file_controller_test.lua , but seems it'snt the place where it is looking for ...
ok, after about 2 hours i can confirm that is a path problem (but i don't know how to solve it!!)
at this time i got a work around , inside the file view_file.htm before calling the function i declare it
local function action_test()
but i'd like if someone can explain me how to use a separate file ...
If you want to do minimal refactoring, try restructuring it this way, with the logic in the View, wrapped in Lua.
Another, probably more appropriate way for the new LuCI, is to put the shell script logic inside a ubus service, like this https://github.com/OnionIoT/smart-lock/blob/master/tutorial/rpcd/onion-lock