Can we write or use C/C++ code or libraries in Corona

I search a lot to internet but not found a real answer.

I need to do complex math operations and will be usefull use libraries written in c/c++ or write a custome one.

The project also need to be compiled to android and ios.

Is this possible?

I found this 
https://docs.coronalabs.com/native/plugin/index.html#native-c

but no example how to do in a real project.

Welcome to the community forums!

Corona operates in two different ways. One is writing 100% of your code in Lua and using our Simulator to test and eventually build a deployable app. We all these simulator builds. The second way is to do what we call “native builds”. With native builds, you would use Xcode or Android Studio to write your native portions of your code (Java, C/C++, Objective C, Swift, etc.) and then write the Corona part of your code in Lua, but you would end up using Xcode or Android Studio to produce a deployable build.

In native programming, you have most of your app in Lua and then for the native portion, there are two ways to write the code, directly using the Lua->C Bridge. Or you can produce a plugin and link it in as a library.

You should start at the top level of the Native documentation instead of starting in the plugin code:

https://docs.coronalabs.com/native/index.html

This tutorial might also be useful for you:
 

https://docs.coronalabs.com/tutorial/native/iosIntro/index.html

Rob

Out of curiosity, what sort of “complex math operations”?

Your solution is write a library for IOS then for Android and then for Windows (if i need) ?
Actualy i use Corona Simulator for test and then build Android apk for deploy to device, when application will work i pass the project to an other person that build for ios.

You say that is possible write a Lua->C Bridge directly but how ? I not found any real exemple for understand how.

The C Bridge have to work for IOS, Android and Windows. From what i found and from your answer i think this is impossible and the only solution to use more low level language is write a specific library for any platform needed.
 

I need to work with algebric functions like A + B * 3 and then calcs the result replacing the label with their values. There are also calcs of integrals and derivate. The base math Lua functions have low decimal precision for me so i also need to rewite them. The algebric formulas also need to be semplified after their creation (es. ( A * 3 + A * B )/ A = 3 + B ).

I wrote a custom code in Lua but it’s really an hard work and performance are poor, so i looking for a different approach.

Thanks for the answers.

If you write in C or C++ that code should work on all supported platforms. You will still need to compile the code for the different platforms. If you need to do simulator builds, then that sounds like you should consider building a plugin and use self-hosted plugins so that everyone on your team can use the simulator.

Rob

Ah, cool. I have some interest in this sort of thing:slight_smile:

From the sounds of it, you might want to look into one of the libraries mentioned in that post, ExprTk. Apparently it can accommodate a variety of number types.

Aside from that, I know “lhf” (Luiz, one of the Lua authors) has some wrappers for various higher-precision libraries. By the sounds of it, ae  (“A general-purpose arithmetic expression package…”) is worth a look as well. (LuaRocks might also have stuff.)

Thx for answer but for now self-hosted plugins  is not in program and made different c compile for any platform also is not in program, but thx for clarifications.

Cool, you posted a lot of interesting links. For now i think i will work again in optimizations of my code, maybe reading your links can help me in improves algoritms or code.

Welcome to the community forums!

Corona operates in two different ways. One is writing 100% of your code in Lua and using our Simulator to test and eventually build a deployable app. We all these simulator builds. The second way is to do what we call “native builds”. With native builds, you would use Xcode or Android Studio to write your native portions of your code (Java, C/C++, Objective C, Swift, etc.) and then write the Corona part of your code in Lua, but you would end up using Xcode or Android Studio to produce a deployable build.

In native programming, you have most of your app in Lua and then for the native portion, there are two ways to write the code, directly using the Lua->C Bridge. Or you can produce a plugin and link it in as a library.

You should start at the top level of the Native documentation instead of starting in the plugin code:

https://docs.coronalabs.com/native/index.html

This tutorial might also be useful for you:
 

https://docs.coronalabs.com/tutorial/native/iosIntro/index.html

Rob

Out of curiosity, what sort of “complex math operations”?

Your solution is write a library for IOS then for Android and then for Windows (if i need) ?
Actualy i use Corona Simulator for test and then build Android apk for deploy to device, when application will work i pass the project to an other person that build for ios.

You say that is possible write a Lua->C Bridge directly but how ? I not found any real exemple for understand how.

The C Bridge have to work for IOS, Android and Windows. From what i found and from your answer i think this is impossible and the only solution to use more low level language is write a specific library for any platform needed.
 

I need to work with algebric functions like A + B * 3 and then calcs the result replacing the label with their values. There are also calcs of integrals and derivate. The base math Lua functions have low decimal precision for me so i also need to rewite them. The algebric formulas also need to be semplified after their creation (es. ( A * 3 + A * B )/ A = 3 + B ).

I wrote a custom code in Lua but it’s really an hard work and performance are poor, so i looking for a different approach.

Thanks for the answers.

If you write in C or C++ that code should work on all supported platforms. You will still need to compile the code for the different platforms. If you need to do simulator builds, then that sounds like you should consider building a plugin and use self-hosted plugins so that everyone on your team can use the simulator.

Rob

Ah, cool. I have some interest in this sort of thing:slight_smile:

From the sounds of it, you might want to look into one of the libraries mentioned in that post, ExprTk. Apparently it can accommodate a variety of number types.

Aside from that, I know “lhf” (Luiz, one of the Lua authors) has some wrappers for various higher-precision libraries. By the sounds of it, ae  (“A general-purpose arithmetic expression package…”) is worth a look as well. (LuaRocks might also have stuff.)

Thx for answer but for now self-hosted plugins  is not in program and made different c compile for any platform also is not in program, but thx for clarifications.

Cool, you posted a lot of interesting links. For now i think i will work again in optimizations of my code, maybe reading your links can help me in improves algoritms or code.