[Plugin] Yet Another Lua Plugin
#1

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:
Код:
#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:
Код:
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).
Reply
#2

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!
Reply
#3

Dope! Lua is bae <3
Reply
#4

Kinda useless.
Reply
#5

This might just get me into Lua all over again.
Reply
#6

Nice work!
Reply
#7

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
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.


THREAD MOVED
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)