08.09.2018, 23:23
(
Последний раз редактировалось IS3; 09.09.2018 в 23:32.
)
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:
This runs "script.lua" from the scriptfiles directory. An example script could look like this:
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).
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); } }
Код:
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!")
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).