Wikia

CHDK Wiki

Changes: Lua/Lua Reference/Native Function Calls

Edit

Back to page

m
(Lua interface to native function calls: update for 1.2, remove interface subject to change message)
 
Line 1: Line 1:
 
==Lua interface to native function calls==
 
==Lua interface to native function calls==
'''This feature is under development and the interface may be subject to change'''
 
 
 
From changeset 864 on, CHDK includes the ability to call Canon [[Event Procedure]]s and arbitrary machine code functions. Together these are referred to as "native" calls.
 
From changeset 864 on, CHDK includes the ability to call Canon [[Event Procedure]]s and arbitrary machine code functions. Together these are referred to as "native" calls.
   
This interface is only available if OPT_LUA_CALL_NATIVE is defined at compile time. Because there are event procedures and other functions which could permanently destroy the camera (for example, by overwriting the canon firmware) it is disabled by default. You must build your own copy of CHDK to use this feature. If you use a third party script which requires this interface, '''it is your responsibility to verify that it is safe'''.
+
As of CHDK 1.2, native function calls may be enabled in the miscellaneous menu. Because there are event procedures and other functions which could permanently damage the camera (for example, by erasing the Canon firmware) this feature is disabled by default and cannot be enabled with set_config_value. If you use a third party script which requires this interface, '''it is your responsibility to verify that it is safe'''. If a script attempts to use native call functions when they are not enabled, a Lua error will be triggered. You can check whether native calls are enabled from script using get_config_value.
  +
  +
For applications where enabling native calls in the menu is not practical, you can build CHDK with OPT_FORCE_LUA_CALL_NATIVE=1 set in buildconf.inc
  +
  +
Prior to release 1.2, native calls were only available as a compile time option.
   
This feature is only available in lua, not ubasic.
+
This feature is only available in Lua, not ubasic.
   
 
The test script [[Lua/Scripts:Standard/Tests/Tstcallf|tstcallf.lua]] can be used to test this functionality, and also serves as an example.
 
The test script [[Lua/Scripts:Standard/Tests/Tstcallf|tstcallf.lua]] can be used to test this functionality, and also serves as an example.

Latest revision as of 18:57, August 10, 2013

Lua interface to native function callsEdit

From changeset 864 on, CHDK includes the ability to call Canon Event Procedures and arbitrary machine code functions. Together these are referred to as "native" calls.

As of CHDK 1.2, native function calls may be enabled in the miscellaneous menu. Because there are event procedures and other functions which could permanently damage the camera (for example, by erasing the Canon firmware) this feature is disabled by default and cannot be enabled with set_config_value. If you use a third party script which requires this interface, it is your responsibility to verify that it is safe. If a script attempts to use native call functions when they are not enabled, a Lua error will be triggered. You can check whether native calls are enabled from script using get_config_value.

For applications where enabling native calls in the menu is not practical, you can build CHDK with OPT_FORCE_LUA_CALL_NATIVE=1 set in buildconf.inc

Prior to release 1.2, native calls were only available as a compile time option.

This feature is only available in Lua, not ubasic.

The test script tstcallf.lua can be used to test this functionality, and also serves as an example.

Interface descriptionEdit

For both event procedures and pointer calls, all arguments after the function pointer or name must be numbers or strings. These are passed to the function as either 32 bit words or pointers to const C strings. If the called function attempts to write to a lua provided string, the results are undefined.

NOTES

  • If a function expects a writable pointer, you must provide one as a number. You can obtain buffers with the AllocateMemory eventproc, and read/write them with peek and poke.
  • It is up to the user to determine what arguments a function expects. Be warned an event procedure may take different arguments on different camera models. Any error in the arguments can crash the camera.
  • Arguments larger than a 32 bit word which are not passed by reference (such as long long or double) must be handled by the caller. Consult the ARM documentation.
  • Return values larger than a 32 bit word are not supported.

call_func_ptr(fptr,...)Edit

fptr is the address of a valid ARM or Thumb function, which uses the normal ARM C calling convention.

Any additional arguments are passed as describe above.

returns the R0 value after the call returns

NOTES

  • You can obtain addresses of CHDK functions from core/main.dump
  • You can obtain addresses of camera functions from stubs_entry*.S

call_event_proc(name,...)Edit

name is the name of a valid, registered Event procedure.

Any additional arguments are passed as describe above.

returns the value returned by ExecuteEventProcedure. This is -1 if the event procedure is not found (or otherwise cannot be executed), or the event procedures own return value. The event procedure may itself return -1, so this cannot be used to determine if the event procedure is available.

NOTES

  • Many event procedures are not registered by default, but can be registered by calling another event procedure. See Event Procedure for details.
  • Event procedures called through exec_event_proc may not use the calling convention you'd expect based on the called functions machine code. See [1]

Around Wikia's network

Random Wiki