LuCI - some noob questions

Hello!

I am newbie in LuCI (but not in sw development) and tried to understand how it works :slight_smile: Sorry for my dumb questions..

Is it possible to call function defined in my module from another module?

I created a function, registered it with entry() in my module index() and would like to call it as target for page from another module. But I've got error "Cannot resolve function"..

my module code:


module("luci.controller.zgroject.zgmodule", package.seeall)

function select_slider()
        luci.http.prepare_content("text/plain")
        luci.http.write("Haha, rebooting now...")
end

function index()
        entry({"zgproject","select_slider"}, call("select_slider"), "SelectSlider" , 80).dependent=false
end

and

I tried to call it from /admin/index.lua

          page.target = call("zgproject/select_slider")

Error

Failed to execute call dispatcher target for entry '/zgproject'.
The called action terminated with an exception:
/usr/lib/lua/luci/dispatcher.lua:818: Cannot resolve function "zgproject/select_slider". Is it misspelled or local?
stack traceback:
	[C]: in function 'assert'
	/usr/lib/lua/luci/dispatcher.lua:818: in function </usr/lib/lua/luci/dispatcher.lua:816>

With best regards,
Vasily

Not sure if it matters, but zgproject is misspelled, it's missing a p.

1 Like

Thank you for your note. Corrected it, but still not work...

No, you cannot reference functions from other controller scopes. You could use an alias() action though to map the page node in admin/index.lua to another one in zgproject/zgmodule

1 Like

O! Thank you! Now it works :slight_smile: