DizzasTeR

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,167
Lua Plugin
«  »Last edited
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

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.

habi

  • Sr. Member
  • Posts: 285
Re: Lua Plugin
« Reply #1,  »
why.. don't know if anyone script in lua.

appreciate your efforts

Inferno

  • Jr. Member
  • Posts: 62
Viva la VU
VFS Developer
VCCNR Administrator

Athanatos

  • Hero Member
  • sin^2(x)+cos^2(x) = 1
  • Posts: 940
Re: Lua Plugin
« Reply #3,  »
Speed performance between LUA and Squirreil when?
Infected City Survival Main Dev

DizzasTeR

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,167
Re: Lua Plugin
« Reply #4,  »Last edited
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
Re: Lua Plugin
« Reply #6,  »
Update
JSON Script Module. Provides following two functions: JSON.stringify and JSON.parse
— Server.shutdown() was missed, added now.

DMWarrior

  • Newbie
  • Posts: 10
Re: Lua Plugin
« Reply #7,  »
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

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,167
Re: Lua Plugin
« Reply #8,  »Last edited
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

  • Newbie
  • Posts: 10
Re: Lua Plugin
« Reply #9,  »Last edited
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
Code: [Select]
----
-- @module MyModule
--
local M = {}

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

return M

Server script
Code: [Select]
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

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,167
Re: Lua Plugin
« Reply #10,  »
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.