Javascript plugin

Started by NewK, Aug 06, 2018, 03:37 AM

Previous topic - Next topic

Klaus

Nice one NewK, keep this going.

EK.IceFlake

#16
Quote from: NewK on Aug 07, 2018, 01:49 PM
Quote from: EK.IceFlake on Aug 07, 2018, 01:13 PMIt'd be nice, but one of the main advantages of JavaScript is the number of libraries there are out there. Most of the libraries that deal with IO stuff won't work because they rely on Node.JS's API.
No, that's not one of the main advantages of javascript, that's one of the main advantages of node.js. Do not mix up the 2, those are 2 very different things. Javascript is not node.js and node.js is not javascript. Node.js is simply a set of C++ APIs that are made available to a javascript context running on top of V8. I never claimed this to be a node.js plugin, I said this is a javascript plugin, as in, actual ecmascript.  Think of it this way: Nodejs is a set of C++ APIs exposed to a javascript context running on V8. This plugin is a set of Java APIs exposed to a javascript context running on V8. Java was used to rely on the already existing VCMP Java plugin to expose VCMP functionality and to share the same codebase so it's easier to maintain in the future.
I'm aware of that, yeah. But the majority of JavaScript libraries that support networking or disk IO are made for node.js. So you won't really get much benefit in using this. ECMAScript by itself is a terrible language. There was this infamous picture which I can't find right now that shows what happens when you're using some operands with different types.

But yeah, overall, it'll still be better than what we currently have.

NewK

Quote from: EK.IceFlake on Aug 08, 2018, 04:59 PMI'm aware of that, yeah. But the majority of JavaScript libraries that support networking or disk IO are made for node.js.  So you won't really get much benefit in using this.
Those are node.js libraries. As I said, this is not a nodejs plugin, so obviously, it's not going to support node.js APIs, that was never my intention with this plugin. It's like comparing LU and VCMP Squirrel IO libraries. Just because both use the same language (squirrel) that doesn't mean all IO operations will look the same. Squirrel's just the "frontend" language, lower level APIs are implemention specific. This is the same case with Javascript, there's many different implementations, but still I wouldn't say there's not "much benefit" seeing as this brings async/non-blocking operations which squirrel does not have and also brings like a 30x speed up improvement. I'd say that's quite some benefits in comparison with squirrel.

Quote from: EK.IceFlake on Aug 08, 2018, 04:59 PMECMAScript by itself is a terrible language. There was this infamous picture which I can't find right now that shows what happens when you're using some operands with different types.
Yea I'm aware of the many javascript quirks and faults. There's some very ugly parts no doubt, but it's getting better and with V8 it becomes a JIT'ed language so yea like you said, overall still better.


ysc3839

That's not what I want. I made Python plugin because Python have much libraries. We can use them instead of write another one.

NewK

Quote from: ysc3839 on Aug 08, 2018, 08:57 PMThat's not what I want. I made Python plugin because Python have much libraries. We can use them instead of write another one.
Yea python's nice, has a big community and is a very productive language but it's just as slow as squirrel. In fact, I found python to be even slower than squirrel. A while back I made a few benchmarks using a recursive function to calculate the first 35 fibonnaci numbers and python was the slowest, these were the results I got:

java - 69ms
javascript - 166ms
squirrel (using SLC's plugin) -  4596ms
python - 4978ms


vitogta

If plugin is done I suggest to write a blank script with few examples inside, then we all could to test it and decide to move on it or no.
The example blank script should include main kill-features of plugin.

NewK

Quote from: vitogta on Aug 09, 2018, 06:00 PMIf plugin is done I suggest to write a blank script with few examples inside, then we all could to test it and decide to move on it or no.
The example blank script should include main kill-features of plugin.
Yea I intend to do this soon. I'm just doing some final adjustments.

Sir. Cucuruchito

#22
I am waiting for this with enthusiasm. Good news approaches.

Everything what we need is a good documentation and it's quite.
Commando Miami 80's
IP: 206.189.97.12:8192


NewK

#23
I've created a sample script that you can see here: https://github.com/newk5/vcmp-javascript-plugin/tree/master/sampleScript/src

It's a very simple script, with basic functionality, it could've been organized better but I chose to keep it as simple as possible to make it easy to understand for everyone. It only has 3 commands: /register,  /login and /stats. It uses SQLite. I've included the DB, it only has a "Players" table with the following columns: id, nickname,password, ip, kills, joins, registerDate, lastActive and level. After registering and logging in, you can use the /stats command to see account info. Note that there is a node_modules folder, this folder should always exist and contains the available modules which at the moment are:

- crypto (for hashing),
- filesystem (disk IO like reading/writing from/to files),
- httpclient (http requests)
- ircbot
- sql (this module works for both SQLite and MySQL and uses the exact same API for both)

I have some more modules planned for the future, like websockets, a discord client and a few other, but for now I just want to make sure the existing modules are stable. I tried to comment most of the code, take a look at the script and if you have any questions feel free to ask.

I'm just doing some final tests at the moment. Soon, I'll provide plugin download links and instructions on how to set it up. After that I'll create some documentation.

Download here