Skip to content

Instantly share code, notes, and snippets.

@Y-Less
Y-Less / MenuExample.pwn
Created July 31, 2015 16:55
SA:MP Menu DSL example
#define T MTitle
#define E MEntry
#define D MDisabled
new MENU:BuyStuff = NewMenu()
% T("Buy Things")
* E("Weapons")
% T("Weapons")
* E("Minigun")
* E("Desert Eagle")
@Y-Less
Y-Less / Menu2.pwn
Created July 31, 2015 17:11
SA:MP Menu DSL 2
#define E MEntry
new MENU:BuyStuff =
NewMenu("Buy Things")
+ ( NewMenu("Weapons")
+ E("Minigun")
+ E("Desert Eagle")
+ E("Knuckle Dusters")
)
+ ( NewMenu("Vehicles")
@Y-Less
Y-Less / Menu3.pwn
Last active August 29, 2015 14:26
SA:MP Menu DSL showing composition
#define E MEntry
new MENU:BuyWeapons =
NewMenu("Weapons")
+ E("Minigun")
+ E("Desert Eagle")
+ E("Knuckle Dusters")
;
new MENU:BuyVehicles =
@Y-Less
Y-Less / MenuDSL2.pwn
Last active August 29, 2015 14:26
SA:MP Menu DSL v2 implementation
enum E_MENU_DATA
{
E_MENU_DATA_TITLE[32],
MenuItem:E_MENU_DATA_FIRST_CHILD,
MenuItem:E_MENU_LAST_LAST_CHILD
}
enum e_MENU_ITEM_TYPE
{
e_MENU_ITEM_TYPE_NORMAL,
@Y-Less
Y-Less / MenuDSL.md
Last active August 29, 2015 14:26
Menu DSL brief tutorial

Operator overloading for code simplification

Introduction

In this tutorial, we will develop a library for creating SA:MP menus. We don't bother with the code for actually displaying the result to the end-user, because it is both simple and irrelevant to the main point. We then look at one trick used to make the code vastly simpler to read and write. First, imagine that we have the following top-level "Buy Things" menu displayed to a user:

 Buy Things 
------------
Weapons
@Y-Less
Y-Less / fontmap.pwn
Created April 19, 2016 17:55
Cunning defines for simple fonts.
#define ________ (0b00000000)
#define _______X (0b00000001)
#define ______X_ (0b00000010)
#define ______XX (0b00000011)
#define _____X__ (0b00000100)
#define _____X_X (0b00000101)
#define _____XX_ (0b00000110)
#define _____XXX (0b00000111)
#define ____X___ (0b00001000)
#define ____X__X (0b00001001)
@Y-Less
Y-Less / reflection.inc
Last active May 28, 2016 15:41
"addressof" and "paramsof" keywords for PAWN functions.
#include <amx_assembly\frame_info>
#include <amx_assembly\disasm>
// This library allows you to get the address of a function at run-time, with
// very little overhead. To do so, just call the "addressof" operator:
//
// printf("Func0 = 0x%08x", addressof (Func0));
//
// However, you can only get the address of a function explicitly enabled for
// for such an operation, otherwise you will get a compile-time error of:
@Y-Less
Y-Less / addressof.inc
Created March 18, 2017 21:48
An experimental include to add `addressof` and `paramsof` function meta information to PAWN.
#include <amx_assembly\frame_info>
#include <amx_assembly\disasm>
// This library allows you to get the address of a function at run-time, with
// very little overhead. To do so, just call "addressof":
//
// printf("Func0 = 0x%08x", addressof (Func0));
//
// However, you can only get the address of a function explicitly enabled for
// for such an operation, otherwise you will get a compile-time error of:
@Y-Less
Y-Less / commandgen.pwn
Last active August 1, 2017 23:16
Generate tests for command processors.
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#include <YSI\y_va>
#include <YSI\y_utils>
fwritef(File:handle, const fmat[], GLOBAL_TAG_TYPES:...)
{
@Y-Less
Y-Less / commandtest.pwn
Last active August 1, 2017 23:38
Run tests for command processors.
#include <a_samp>
#define YSI_NO_MASTER
new
gCommands[][32] = {
#include "../scriptfiles/all_tests.pawn"
""
};