how to check if a function (native call) is enabled - LUA Scripting - CHDK Forum

how to check if a function (native call) is enabled

  • 6 Replies
  • 3948 Views
*

Offline Mlapse

  • *****
  • 584
  • S95 S110
how to check if a function (native call) is enabled
« on: 16 / August / 2020, 07:22:41 »
Advertisements
Sometimes with LUA I feel like an egyptologist without a rosetta stone....I'm just making it up as I go along.

How to check if native call is enabled in CHDK?

I could not find an example, so my first thought was:

if get_config_value(999) == false then  -- native call id =999*
    printf("native call disabled")
else

and that did not work, then I came across something in a script that didn't do it for me either  :)

if (type(call_event_proc) ~= "function" ) then
    printf("native call disabled")
else

Where can I find the documentation for the proper way to do this? Or can somebody explain why get_config_value(999) does not work.
*I pulled that number from
http://subversion.assembla.com/svn/chdk/trunk/core/conf.c
« Last Edit: 16 / August / 2020, 10:44:22 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14125
Re: how to check if a function (native call) is enabled
« Reply #1 on: 16 / August / 2020, 14:46:31 »
This is kind of bug,  but you you can't read config 999 from script (edit: incorrect, see Phil's comment below), and type(call_event_proc) ~= "function" ) hasn't worked since Lua was turned into a module.

If you really want to know, you can try to call a no-existent or harmless eventproc inside pcall, like

Code: [Select]
if not pcall(call_event_proc,'check_chdk_native_calls')) then
 print('native calls not available!')
end

« Last Edit: 16 / August / 2020, 18:33:47 by reyalp »
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: how to check if a function (native call) is enabled
« Reply #2 on: 16 / August / 2020, 15:31:53 »
very creative solution reyalp, thanks.
frustration is a key ingredient in progress

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: how to check if a function (native call) is enabled
« Reply #3 on: 16 / August / 2020, 17:36:10 »
Wouldn't the native calls config value be get_config_value(1999)?

I haven't tested this, so there may be some other reason it won't work.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: how to check if a function (native call) is enabled
« Reply #4 on: 16 / August / 2020, 17:56:58 »
thanks, but as reyalp stated this does not work, i think 1999 was from pre 1.2
the creative solution is the way to go.
frustration is a key ingredient in progress

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: how to check if a function (native call) is enabled
« Reply #5 on: 16 / August / 2020, 18:26:12 »
thanks, but as reyalp stated this does not work, i think 1999 was from pre 1.2
the creative solution is the way to go.


 :) As the author of the config changes made in 1.3 I do know a bit about this.
The native call config value in 1.2 and earlier was 119 - the mapping table converts this to 1999 if you try and load a 1.2 config save file.


The config numbers are offset so the file they are stored in can be determined - the core config values start at 1000 (see CHDK/LUALIB/GEN/cnf_core.lua).
This offset is also used so scripts can access the correct set of config values.
Even though the config value appears to be 999 in conf.c the actual value is 1999.


BTW - I tested this with chdkptp and it does work.


Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: how to check if a function (native call) is enabled
« Reply #6 on: 17 / August / 2020, 01:57:34 »
thanks philmoz,
so now I have to choose from 3 possible solutions for the same problem....It'll work one way or the other.
frustration is a key ingredient in progress

 

Related Topics


SimplePortal © 2008-2014, SimplePortal