Understanding Lua Event Procedures - Script Writing - CHDK Forum
supplierdeeply

Understanding Lua Event Procedures

  • 2 Replies
  • 69 Views
Understanding Lua Event Procedures
« on: 26 / January / 2023, 12:01:01 »
Advertisements
@reyalp

I hope you can throw some education my way?

As I try and up my Lua scripting skills, it is clear I don't fully understand Event Procedures.

So far I've explored FA and MECHA listings.

Let's say I'm only looking to code on my M3.

The first question is, do I need to call FA.create and MECHA.create?

If I don't, for example, FocusPositionWithLensCom works fine.

Then there is the question over what 'calls' to make, eg: FocusPositionWithLensCom vs MoveFocusLensWithPosition.

So, any hints would be welcome ;-)

Cheers

Garry


*

Offline reyalp

  • ******
  • 13840
Re: Understanding Lua Event Procedures
« Reply #1 on: 26 / January / 2023, 14:34:11 »
As I try and up my Lua scripting skills, it is clear I don't fully understand Event Procedures.
Event Procedures (aka eventprocs) are internal Canon functions built into the firmware, for their own development / service needs and scripting language.

CHDK Lua is only involved to the extent that it provides an interface to call them.

Eventprocs are useful because they provide us with Canon's own names for some firmware functions, which in turn provides some clues about what they do. They also frequently do useful things. Because of this, the CHDK sig finders also detect many of them (along with many other functions), which generates the lists in the funcs_by_*.csv files.

Quote
So far I've explored FA and MECHA listings.
Note: Case matters, so it's FA.Create and Mecha.Create.
Quote
Let's say I'm only looking to code on my M3.

The first question is, do I need to call FA.create and MECHA.create?

If I don't, for example, FocusPositionWithLensCom works fine.
Eventprocs need to be "registered" to be used. Registering associates the name with address of the machine code. Some are registered by default, some are registered by calling other evenprocs, usually named something like Whatever.Create or RegisterWhateverSomething.

To find out whether an eventproc is registered, you either need to reverse engineer the firmware, or call it and check the return value. The return value will be -1 if the function isn't registered. Of course, a registered function could also return -1, but this is fairly rare, if the function doesn't otherwise return a value, Canon generally uses 0 for success.
If you have access to the camera UART, the Event Shell will also tell you whether a function is registered, or give you a list in response to ?
Quote
Then there is the question over what 'calls' to make, eg: FocusPositionWithLensCom vs MoveFocusLensWithPosition.
Tired: Judging books by their cover
Wired: Judging functions by their name

If you want more than just guessing based on the name, reverse engineering is required to understand more about the parameters, usage and purpose. Ghidra is by far the best freely available tool for this, but a fair a bit of reverse engineering knowledge is required to use it effectively.
Don't forget what the H stands for.

Re: Understanding Lua Event Procedures
« Reply #2 on: 26 / January / 2023, 15:35:48 »
Many thanks for finding the time for feedback

 

Related Topics