LiquidPlayer / LiquidCore

Node.js virtual machine for Android and iOS
MIT License
1.01k stars 127 forks source link

Using Javascript foreign libraries #11

Closed kaushikthedeveloper closed 7 years ago

kaushikthedeveloper commented 7 years ago

Hello,

I am new to the android development world and am currently working on a pet project. The problem I currently face is that I need to include a Javascript library called BigNumber in my project. And since this does not have any supported jar files, the only thing I can think of is to go for library like LiquidCore that lets me access Javascript functionalities in android.

My question : Is it possible to load external api for JavaScrpit libraries like , and if so, how?

Fingers crossed!!!

ericwlange commented 7 years ago

Yes, you should be able to use LiquidCore for this.

As of 0.1.0, the process for running node modules is a bit of work. Version 0.2.0, which I am hoping to release shortly, makes this much simpler. The HEAD version of the repository works pretty well, but I have not yet written any documentation.

But basically, you want to browserify your code into a single .js file (using the --node flag), and load it into a LiquidCore MicroService. You can then interact with the code using the LiquidEvents event emitter object.

I know this may seem cryptic, but this is the best I can do without writing proper documentation. If you can be patient until 0.2.0 is released, it should be clearer :) Otherwise, this is completely doable with the current repo. But it will take some trial and error.

kaushikthedeveloper commented 7 years ago

That was a quick reply :D Good to hear I can load js libraries with LiquidCore.

Since I am a bit short on time, I'll have to check it out with 0.1.0 release itself. I know you guys will be busy, but could you maybe give a short HowTo into this. I know many people who would benefit from this. Maybe just how to load the module from .js file and print value returned by a dummy function foo(). Nothing more asked.

Thanks for the help again!!!

tomholub commented 7 years ago

Yup - a Hello World example of importing a JS module and calling a function in it would be extremely useful.

ericwlange commented 7 years ago

Ok, I have a prerelease of 0.2.0 available and I have written a Hello World example that explicitly includes bignumber.js. Please see the WIP documentation and give it a try. Let me know if it works.

ericwlange commented 7 years ago

Version 0.2.0 is now released.