Lua Plugin

Started by DizzasTeR, Nov 05, 2020, 12:53 PM

Previous topic - Next topic

DizzasTeR

Here's a Lua plugin for VCMP. It lets you script in Lua (No sh!t Sherlock :o) Also because python sucks kekw @Shad

https://github.com/DizzasTeR/VCMP-Lua

Downloads are available in the release section over at GitHub

Features:
  • Complete API coverage
  • Async features for database operations
  • Multiple utility libraries (Json, web requests, etc)
  • The power of Lua modules
  • Better API
  • Developer friendly

Blank Script (Lua Version): https://github.com/DizzasTeR/VCMP-Lua/wiki/Blank-Script

Important: You need OpenSSL (F**K MySQL and everything related to it): https://slproweb.com/products/Win32OpenSSL.html OR Just place the two DLLs available with plugin download and place them in server directory

If you are going to try this out, I've written a README on GitHub which you should totally check out. I've also written as much wiki on github as I could and its written enough to let anyone be able to do stuff.

Note: Please know that I may have missed some functions of VCMP, if someone is actually going to use this and you come across a functionality that doesn't exist, let me know I can try looking into it.

:edit: You CAN set up LuaRocks or LuaDist to use third-party pre-made lua libraries but I didn't really test them, so if you are really into Lua, you may try that.

Inferno

Viva la VU
VFS Developer
VCCNR Administrator

NicusorN5

Speed performance between LUA and Squirreil when?

DizzasTeR

#3
While there's more evidence towards Squirrel being more "efficient" than Lua because it provides functionality based on your needs (Take static and dynamic arrays in squirrel for example, you use one which fits more) however in Lua you just straight up throw Tables for anything and it just works. Both languages are close, one has advantages over the other.

However LuaJIT is faster than Squirrel I believe.

:edit: Also Lua is actively maintained right now and more popularly supported

DizzasTeR

Update
— Added SQLite3 Module (https://github.com/DizzasTeR/VCMP-Lua/wiki/SQLite3-Module)
— Small new features & logical fixes

Quote from: Athanatos on Nov 06, 2020, 05:24 PMSpeed performance between LUA and Squirreil when?
After testing, faster than squirrel. How much and in what scenarios is subjective.

DizzasTeR

Update
JSON Script Module. Provides following two functions: JSON.stringify and JSON.parse
— Server.shutdown() was missed, added now.

DMWarrior

Good work! Lua support can be very interesting, not only due to it's popularity, but because it has more libraries avaliable than Squirrel, too.

I still don't know what I could do with it, though. But for anyone interested in giving a try, I managed to rewrite most of the VC:MP Blank Server to Lua, as well looking through each function and finding which ones are missing. The only problem is that SendDataToClient() doesn't work, but everything else seems to be fine.

This, alongside the Wiki, should be enough for getting started:
VC:MP Blank Server (Lua Script)

DizzasTeR

#7
Such an amazing contribution @DMWarrior

I've looked through the code and everything seems great, I don't know regarding the SendDataToClient failing to work but I'm sure I did test all the stream stuff however I'll double check it again. However I would rather just recommend using the JSON module to just send a nice JSON string as a single string and then using the squirrel json script on client side to decode it back, its one of the easiest and best ways to just send info back and forth.

It seems you made a mistake writing the SendDataToClient function, when you're taking the stramType from argument[1], you no longer need to include the first parameter in your further data extraction, you should be going through arguments[2] to #arguments or basically #arguments - 1 (Updated version of your script is now on github with a fixed SendDataToClient)

I will also add that script to the github wiki as a source of code example and getting started.
:edit: Available now: https://github.com/DizzasTeR/VCMP-Lua/wiki

DMWarrior

#8
I made some minor changes on Blank Server:
Updated Blank Server (Lua script)

After setting up "package.path", we can easily load modules with require(). For anyone who's not familiar with Lua, here's an example:

MyModule.lua
----
-- @module MyModule
--
local M = {}

----
-- A function.
--
function M.hello()
  print("Hello, world!")
end

return M

Server script
local MyModule = require("MyModule")
MyModule.hello()

And since Lua has no classes, libraries like middleclass can be extremely useful, specially when combined with modules. It's easier to work with in comparison to Squirrel, at least in my opinion.

After noticing that VEH_ constants are missing, I decided to make a very simple list, too:
Vehicles List (Lua Script)

Nothing amazing or interesting yet, though, but it may gain some more interest once there's more scripts available to work with. One idea would be rewrite some scripts from Squirrel to Lua so they could be used as example or base for other scripts. I don't know if anyone would do it, but I could try doing this with some of my scripts to see how it looks.

DizzasTeR

Lua Plugin 2.0 Beta released

After knowing some interesting people who started using this plugin, the development and updates have been going strong to add the remaining bits and features.

The latest 2.0 release provides a CPR module which gives you access to Remote.fetch and Remote.post. More on them on wiki.

habi