SA-MP Forums

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

Closed Thread
Thread Tools Display Modes
Old 09/09/2018, 12:23 AM   #1
Join Date: Aug 2018
Posts: 2
Reputation: 11
Default Yet Another Lua Plugin

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).

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.

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

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


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

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; 10/09/2018 at 12:32 AM.
IS3 is offline  
Old 09/09/2018, 12:26 AM   #2
Join Date: Aug 2014
Location: Hamburger
Posts: 1,284
Reputation: 461
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!
J0sh... is offline  
Old 09/09/2018, 12:39 AM   #3
Join Date: May 2017
Location: Iran
Posts: 113
Reputation: 191
Default Re: Yet Another Lua Plugin

Dope! Lua is bae <3
iAmir is offline  
Old 27/09/2018, 04:12 PM   #4
nGen.SoNNy's Avatar
Join Date: Sep 2009
Location: Romania
Posts: 928
Reputation: 69
Default Re: Yet Another Lua Plugin

Kinda useless.
If i've helped you, please click
nGen.SoNNy is offline  
Old 27/09/2018, 05:00 PM   #5
Eoussama's Avatar
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,071
Reputation: 281
Default Re: Yet Another Lua Plugin

This might just get me into Lua all over again.

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

|===[Interesting topics]===|
Semantic Versioning
Eoussama is offline  
Old 27/09/2018, 05:22 PM   #6
Little Clucker
Mazio's Avatar
Join Date: Sep 2018
Location: India
Posts: 42
Reputation: 22
Default Re: Yet Another Lua Plugin

Nice work!
Mazio is offline  
Old 27/09/2018, 07:57 PM   #7
Big Clucker
IllidanS4's Avatar
Join Date: Feb 2013
Posts: 196
Reputation: 275
Default Re: Yet Another Lua Plugin

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.

You have stolen my dreams and my childhood, and you have stolen my sleep hours.

Last edited by IllidanS4; 26/10/2018 at 03:08 PM.
IllidanS4 is offline  
Closed Thread

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 01:18 AM
[MySQL] From StickenKid's plugin to BlueG's plugin jessejanssen Scripting Help 2 15/06/2014 02:20 AM
MySQL Plugin R5 plugin problem dud Scripting Help 12 05/12/2011 07:28 PM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 03:32 PM

All times are GMT. The time now is 04:46 AM.

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