Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new functions in lua script #5188

Closed
jufpv opened this issue Aug 29, 2017 · 5 comments
Closed

Implement new functions in lua script #5188

jufpv opened this issue Aug 29, 2017 · 5 comments

Comments

@jufpv
Copy link

jufpv commented Aug 29, 2017

Hello I'm new in openTX (I've not received my horus yet, bought today)
I would like to know the clean way to create my own cpp functions in order to use it in lua scripts.
So which file(s) I have to modify ?
In fact I would like to add functionalities to lua scripts, for example how did you add function crossfireTelemetryPop() in openTX firmware / lua language ?
Thank you ! :)

@jufpv jufpv changed the title Create new cpp function that can be used by lua script Implement new functions in lua script Aug 30, 2017
@jufpv jufpv closed this as completed Aug 31, 2017
@projectkk2glider
Copy link
Member

@jujuducoin why did you close this? Are you still interested? I can write a small howto.

@jufpv
Copy link
Author

jufpv commented Sep 1, 2017

I closed because it is not really an issue ^^
But if you can do this it would be really nice !

@jufpv jufpv reopened this Sep 1, 2017
@projectkk2glider
Copy link
Member

First I would encourage you to discuss your ideas for new functions before actually implementing them. This will give you a broader view and much more chance of you final code being included in the official OpenTX. You can talk to us on https://opentx.rocket.chat/channel/OpenTX_General

Now to the implementation:

Each Lua API function is:

  • declared in appropriate table (each module has one such table) - this provides a link between Lua function name and C function name
  • implemented as actual C function that does something.

Lets take your example `crossfireTelemetryPop()'. The function belongs to the general part of OpenTX API and is defined in

{ "crossfireTelemetryPop", luaCrossfireTelemetryPop },

As you can see the C function is named luaCrossfireTelemetryPop and is implemented in the same file at

static int luaCrossfireTelemetryPop(lua_State * L)

How the function itself is implemented:

  • function gets parameters that were passed to it from Lua function call (this exact function is a bad example since it doesn't take any parameters, but look a other functions).
  • it then calls appropriate existing OpenTX functions
  • prepares result (a return value of Lua function)

You can read more at https://www.lua.org/pil/26.1.html

@jufpv
Copy link
Author

jufpv commented Sep 1, 2017

For the moment I'm just trying but after that why not to purpose some changes
Thx you save my time :)

@stale
Copy link

stale bot commented Aug 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 17, 2019
@stale stale bot closed this as completed Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants