SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 08/09/2018, 11:23 PM   #1
IS3
Banned
 
Join Date: Aug 2018
Posts: 2
Reputation: 11
Default Yet Another Lua Plugin


Introdution
There has been a number of plugins enabling writing SA-MP scripts in Lua, but most of them became quickly unmaintained, and couldn't cover all functions from other common SA-MP plugins. YALP behaves in a fundamentally different way instead of registering every SA-MP function via C, it allows interaction between the Lua script and SA-MP via a dynamically created or loaded AMX machine, registered as a normal filterscript. Using extensive hooking, it intercepts all operations performed on the filterscript (or gamemode) and translates them to operations on the Lua instance.

Thanks to this mechanism, neither you nor the plugin has no "declare" any native or public function. Instead, using two special tables, it is possible to dynamically look for any native function, or register any public function. The plugin translates all calls between SA-MP and Lua and converts automatically between Lua and Pawn types. Therefore, it doesn't have to maintain any information about available Pawn functions, and so there is no risk of it making certain SA-MP functions unavailable (if some ever get added). It also automatically supports all plugin functions.

At the moment, all Pawn types and mechanisms are supported (even PawnPlus asynchronous calls).

Configuration
The plugin is meant to be lightweight and not very tightly connected to the server, so the only (little) configuration is done from Pawn. There is also no new script or resource system that you need to learn, you simply load a Lua script and all is done.

Examples
It is very easy to set up a new Lua instance from Pawn and run your own scripts:
Code:
#include <a_samp>
#include <YALP>

public OnFilterScriptInit()
{
    new Lua:l = lua_newstate(lua);
    if(lua_loadfile(l, "script.lua") || !lua_bind(l))
    {
        lua_stackdump(l);
        lua_close(l);
    }
}
This runs "script.lua" from the scriptfiles directory. An example script could look like this:
Code:
local interop = require "interop"
local public = interop.public
local SendClientMessage = interop.native.SendClientMessage

local COLOR_WHITE = 0xFFFFFFFF

function public.OnPlayerConnect(playerid)
  SendClientMessage(playerid, COLOR_WHITE, "Hello from Lua!")
end

print("Lua script initialized!")
For more detailed example, please see the tutorial.

Other features
Timers, independent on SeTimer(Ex), and remoting allowing communication between two separate Lua instances. Also provides some new functions to standard Lua packages (function manipulation, asynchronous programming etc.), and might even extend the language itself to allow new constructs in the future (like references).

Last edited by IS3; 09/09/2018 at 11:32 PM.
IS3 is offline   Reply With Quote
Old 08/09/2018, 11:26 PM   #2
J0sh...
High-roller
 
J0sh...'s Avatar
 
Join Date: Aug 2014
Location: Hamburger
Posts: 1,293
Reputation: 401
Default Re: Yet Another Lua Plugin

a week. you know what i'm talking about.

Took you long enough to release it especially when you was shilling it in screenshots on discord!
__________________
🍔🍔🍔🍔🍔🍔🍔🍔🍔🍔🍔🍔
Yes I know my name has 3 dots.
Thanks for noticing, it was meant to signify a pause in the personal message asking to be named J0sh but they got included.
J0sh... is offline   Reply With Quote
Old 08/09/2018, 11:39 PM   #3
iAmir
Big Clucker
 
iAmir's Avatar
 
Join Date: May 2017
Posts: 99
Reputation: 164
Default Re: Yet Another Lua Plugin

Dope! Lua is bae <3
__________________
Quote:
Originally Posted by J0sh...
haha
iAmir is offline   Reply With Quote
Old 27/09/2018, 03:12 PM   #4
nGen.SoNNy
High-roller
 
nGen.SoNNy's Avatar
 
Join Date: Sep 2009
Location: Romania
Posts: 1,000
Reputation: 65
Default Re: Yet Another Lua Plugin

Kinda useless.
__________________
If i've helped you, please click
nGen.SoNNy is offline   Reply With Quote
Old 27/09/2018, 04:00 PM   #5
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,275
Reputation: 255
Default Re: Yet Another Lua Plugin

This might just get me into Lua all over again.
__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning


Eoussama is offline   Reply With Quote
Old 27/09/2018, 04:09 PM   #6
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,954
Reputation: 1548
Default Re: Yet Another Lua Plugin

Nice! Now that I've read the extended description, I really like what this plugin is doing (despite not really being a fan of Lua). I attempted to do a very similar thing a couple of years ago with Python but it was never finished (for various reasons).

This looks genuinely useful for delegating certain tasks to a different language. Can you make use of any Lua packages via package managers? I'm thinking of things such as database interfaces and stuff.

Nice work!
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 27/09/2018, 04:22 PM   #7
Mazio
Little Clucker
 
Mazio's Avatar
 
Join Date: Sep 2018
Location: New Delhi, India
Posts: 25
Reputation: 13
Default Re: Yet Another Lua Plugin

Nice work!
Mazio is offline   Reply With Quote
Old 27/09/2018, 06:57 PM   #8
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 288
Reputation: 120
Default Re: Yet Another Lua Plugin

Quote:
Originally Posted by [HLF]Southclaw View Post
Nice! Now that I've read the extended description, I really like what this plugin is doing (despite not really being a fan of Lua). I attempted to do a very similar thing a couple of years ago with Python but it was never finished (for various reasons).

This looks genuinely useful for delegating certain tasks to a different language. Can you make use of any Lua packages via package managers? I'm thinking of things such as database interfaces and stuff.

Nice work!
Thanks! For 0.2, require will be usable as the standard method of importing packages (Lua or C). It looks into "scriptfiles/lua" and "plugins" and tries to find a compatible package there. Some advanced package management is beyond what were my intentions for this plugin; I'd like to provide the base features so that the rest can be easily made in Lua.
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 

kingsofsa.cz:8888 running Cinematic Mode
IllidanS4 is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Centos7 - Streamer plugin and crashdetect plugin Su37Erich Server Support 3 12/08/2016 12:18 AM
[MySQL] From StickenKid's plugin to BlueG's plugin jessejanssen Scripting Help 2 15/06/2014 01:20 AM
Very good plugin suggestion (for scripters) and easy to make for the Plugin Developers! Xentiarox Plugin Development 5 29/07/2012 10:48 PM
MySQL Plugin R5 plugin problem dud Scripting Help 12 05/12/2011 06:28 PM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 02:32 PM


All times are GMT. The time now is 07:43 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.