Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Scripting Q&A => Topic started by: garry23 on November 14, 2016, 06:02:15 PM

Title: Lua question re script 2 script communication
Post by: garry23 on November 14, 2016, 06:02:15 PM
David

If you are able to give me a pointer regarding this question that would be great.

Say I have two scripts, A and B.

Can I call a function in A from within B?

If so, how  ;)

Cheers

Garry
Title: Re: Lua question re script 2 script communication
Post by: dmilligan on November 15, 2016, 04:01:14 AM
No, not directly. Can you describe more precisely what you are trying to do? and what is your goal? Reuse some common code? Or a communication channel?
Title: Re: Lua question re script 2 script communication
Post by: garry23 on November 15, 2016, 07:31:46 AM
David

Script A does certain things, as does s riot B.

Script A runs directly from pressing keys, i.e. you don't go through the ML menu. Script B only operates through the ML menu.

I could combine A and B into a new script C, with combined functionality, and this is what I might do.

The alternative I thought was to extend the functionality of A by running some of the functions in B, from A.

But from what I know and what you are implying, I think I just write a single mother of all scripts, i.e. A combined script C. Or lift the functions from A into C.

Cheers

Garry
Title: Re: Lua question re script 2 script communication
Post by: dmilligan on November 15, 2016, 01:00:45 PM
If you just want to reuse some common code, you can put that code in a script in the lib folder and load it like a library with require(). If the two scripts need to share state, then you probably ought to combine them.