1. Luaj requires to load Lua script and call it for declare functions, etc. Currently, I'm calling main.lua, but it starts to chdkptp itself, with calls to dngcli.init_cli(), etc. i.e. many things that not need to my framework. Could you move startup code that initializes some thing and includes all required lua files("fsutil=require'fsutils'") into separate file (probably init.lua ?) ? After that, main.lua can just include this startup code and run usual methods. I will use init.lua, then will get required function and call from java. main.lua will not be loaded in my code, but will be still used in chdktptp.
I'll look into splitting this up more, but you might also consider just writing your own lua file. Aside from the requires at the top, it's almost all dealing with command line options and startup stuff you don't need.
Of the top of my head, the other things you might want are
the prefs._add lines, the con global, and get_chdkptp_home
2. It would be good all functions (that can be called in chdkptp from java) as separate functions with table parameters. I.e. something like this:
function remoteshoot(params)
if (params.raw) ...
if (params.isomode>200) ...
...
But I understand that is big changes. I will send just array with text parameters yet. But how can I get remoteshoot function ? I see cli:add_commands but I don't know Lua so good to understand hot to get function by name. Could you please to write me simple Lua script for just get and call 'remoteshoot' function ? Somethins like :
func = table.get('remoteshoot')
func(['-raw','-isomode=100'])
The simplest way is to just use cli:execute and build the full command as a string. See gui_user.lua for an example of this with remoteshoot. This is the recommended way to call cli commands.
If you really want to call the function directly, you could use cli.names.commandname:func(), like
cli.names.help:func({v=true,'help'})
Note that :func expects the args to have already been parsed by the commands parse function (cli.names.commandname.args:parse), so you'd need to supply them in the appropriate table.
This varies by command, you'll need to look in the definitions in the cli:add_commands section, but it's a bit like what you requested in the first part. For most commands, the -x options are named elements in the table, and other arguments (like file names etc) are in the array part of the table.
Defaults are in the argparser, so if you bypass that you will have to provide them yourself. Things that default to false can probably be left out most of the time, but there may be cases where false behaves differently from nil.
FWIW, I never intended the CLI to be called this way (outside of cli:execute), it's an "internal" interface and I'm not likely to spend effort keeping it backward compatible if I need to make changes.
3. If capture_get_data_pcall throws some error, script just dumps this error and continues to work. I.e. I can't know from my code was remoteshoot processed good or not. Is it possible to change code somehow(additional error throing or status return) for be able to check status on the remoteshoot function end ?
The cli command :func or cli:execute will usually return status, <error message>. If you use cli:execute, it will normally be protected by xpcall, so any lua errors will be caught and turned into an error message. If you call :func directly, it's possibly you will get lua errors. In chdkptp, errors may be a table or a string (the table does have a tostring metamethod)