加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 6049 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   

头像
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: *
推文 x 鲜花 x
分享: 转寄此文章 Facebook Plurk Twitter 版主评分版主评分版主评分 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x2
[程式] 实现AMXX物件导向编程(OOP)的模块 1.10 版本 (2024/6/28 更新)  (模块 DLL)
原创文章

此文章被评分,最近评分记录
财富:500 (by amore12) | 理由: 辛苦了!!


献花 x4 回到顶端 [楼 主] | Posted:2023-07-13 18:16 |
cyxnzb 会员卡
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x0 鲜花 x6
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

这个直观来说能实现什么功能呢请问


献花 x0 回到顶端 [1 楼] From:未知地址 | Posted:2023-07-14 17:43 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x46 鲜花 x101
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

下面是引用 cyxnzb 于 2023-07-14 17:43 发表的 : 到引言文
这个直观来说能实现什么功能呢请问

这其实不是实现甚么功能的, 这是让编写插件的人能使用OOP的方式来写插件, 让插件开发过程更方便

使用OOP来写东西的好处是能减少重复的程式码, 程式可被高度重复使用, 减少撰写程式错误的风险, 程式更加易于维护 易扩展

详情可以到各大搜寻引擎找找看 "OOP" 或者 "物件导向程式设计", 希望能解答到你的疑问 表情

此文章被评分,最近评分记录
财富:300 (by amore12)


献花 x1 回到顶端 [2 楼] From:香港没有资料 | Posted:2023-07-14 18:18 |
Nailaz 手机
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖 创作大师奖
小有名气
级别: 小有名气 该用户目前不上站
推文 x77 鲜花 x254
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

酷东西,对程式好有热忱啊!


web front-end and software engineer.
献花 x2 回到顶端 [3 楼] From:台湾中华电信股份有限公司 | Posted:2023-07-17 10:21 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x46 鲜花 x101
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

更新 2023-7-28:
重写内核,使用 AMTL 取代 STL,修正 linux 下崩溃的问题
帖子里加入了新的下载连结


[ 此文章被11922911在2024-03-15 20:41重新编辑 ]

此文章被评分,最近评分记录
财富:300 (by amore12) | 理由:


献花 x3 回到顶端 [4 楼] From:香港没有资料 | Posted:2023-07-28 01:25 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x46 鲜花 x101
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

更新 版本 1.1.0 (2024-3-15) :
加入多重继承功能 (详见 oo_multiple_inheritance.sma), 多重继承是仿照类似 python 的 MRO order
修正 oo_get 和 oo_set 不能使用类别名称搜索 ex: oo_get(@this, "Class@var")

多重继承范例:
#include <amxmodx>
#include <oo>

public oo_init()
{
     oo_class("B1");
     {
           oo_var("B1", "a", 1);
           oo_ctor("B1", "Ctor", @cell);
           oo_mthd("B1", "Print");
           oo_mthd("B1", "Method1");
     }

     oo_class("B2");
     {
           oo_var("B2", "b", 1);
           oo_ctor("B2", "Ctor", @cell);
           oo_mthd("B2", "Print");
           oo_mthd("B2", "Method2");
     }

     oo_class("D", "B1", "B2");
     {
           oo_var("D", "hp", 1);
           oo_ctor("D", "Ctor", @cell, @cell, @cell);
           oo_mthd("D", "Print");
     }
}

public plugin_init()
{
     new obj = oo_new("D", 100, 689, 777);
     oo_call(obj, "Print");
}

public B1@Ctor(a) { oo_set(oo_this(), "a", a); }

public B2@Ctor(b) { oo_set(oo_this(), "b", b); }

public D@Ctor(hp, a, b)
{
     oo_super_ctor("B1", a);
     oo_super_ctor("B2", b);
     oo_set(@this, "hp", hp);
}

public D@Print()
{
     oo_call(@this, "Method1");
     oo_call(@this, "Method2");

     oo_call(@this, "B1@Print");
     oo_call(@this, "B2@Print");
     server_print("D@Print(hp=%d, a=%d, b=%d)",
           oo_get(@this, "hp"),
           oo_get(@this, "a"),
           oo_get(@this, "b"));
}

public B1@Method1() { server_print("B1@Method1()"); }
public B2@Method2() { server_print("B2@Method2()"); }

public B1@Print() { server_print("B1@Print()"); }
public B2@Print() { server_print("B2@Print()"); }

输出结果
B1@Method1()
B2@Method2()
B1@Print()
B2@Print()
D@Print(hp=100, a=689, b=777)


[ 此文章被11922911在2024-03-17 10:29重新编辑 ]


献花 x1 回到顶端 [5 楼] From:香港没有资料 | Posted:2024-03-15 20:37 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x46 鲜花 x101
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

今天在 GitHub 最新的 commit 加入了一个实验性的功能, 但还在测试中
这个功能是 HOOK 挂钩系统, 有了这功能你就可以挂钩所有插件的 OO 方法/建构和解构子

如果你想测试, 你可以到我那个 repo 的 Actions 页面下载最新由 GitHub workflows 自动建置生成好的档案
和下载最新的 oo.inc

档案会在 Action 中的 Artifacts 的区块 (你需要登入 GitHub 才能查看可以下载的档案)



HOOK 挂钩系统 详细使用方法:
(在这个例子中我们将挂钩 oo_animal.sma 中的东西)

复制程式
#include <amxmodx>
#include <oo>

public plugin_init()
{
       // 挂钩 Animal@Ctor() 的建构子
       oo_hook_ctor("Animal", "Ctor", "OnAnimalCtor");

       // 挂钩 Dog@MakeSound() 方法 (post事件)
       oo_hook_mthd("Dog", "MakeSound", "OnDogMakeSound_Post", 1);

       // 挂钩 Snake@GetLegs() 方法
       oo_hook_mthd("Snake", "GetLegs", "OnSnakeGetLegs_1");
       oo_hook_mthd("Snake", "GetLegs", "OnSnakeGetLegs_2");

       // 挂钩 Snake@Test() 方法
       oo_hook_mthd("Snake", "Test", "OnSnakeTest");

       // 挂钩 Animal@Dtor() 的解构子
       oo_hook_dtor("Animal", "OnAnimalDtor");
}

public OnAnimalCtor(const name[], age)
{
       server_print("OnAnimalCtor(name=%s, age=%d)", name, age);
}

public OnDogMakeSound_Post(msg[], len)
{
       server_print("OnDogMakeSound_Post(msg=%s, len=%d)", msg, len);
}

public OnSnakeGetLegs_1()
{
       server_print("OnSnakeGetLegs_1()");
       oo_hook_set_return(369); // 改变这方法原本回传的值
       return OO_CONTINUE;
}

public OnSnakeGetLegs_2()
{
       server_print("OnSnakeGetLegs_2() => oo_hook_get_return()=%d", 
              oo_hook_get_return()); // 获取之前改变了的回传值

       return OO_SUPERCEDE; // 阻止原本这方法的执行
}

public OnSnakeTest(a, &b, const c[], d[], e[5])
{
       server_print("OnSnakeTest(%d, %d, %s, %s, {%d,%d,%d,%d,%d})", a, b, c ,d, e[0], e[1], e[2], e[3], e[4]);

       // 改变第 1 个参数 a 的值做 11
       oo_hook_set_param(1, OO_CELL, 11);

       // 改变第 2 个参数 b 的值做 22 (因为类型是 OO_BYREF 可以直接改)
       b = 22;

       // 改变第 3 个参数 c 的值做 "33"
       oo_hook_set_param(3, OO_STRING, "33");

       // 改变第 4 个参数 d 的值做 "44" (因为类型是 OO_STRING_REF 可以直接改)
       copy(d, 31, "44");

       // 改变第 5 个参数 e 的值做 {11, 22, 33, 44, 55}
       new arr[5] = {11, 22, 33, 44, 55};
       e = arr; // 因为类型是 OO_ARRAY 可以直接改
}

public OnAnimalDtor()
{
       server_print("OnAnimalDtor()");
}


[ 此文章被11922911在2024-06-28 17:46重新编辑 ]


献花 x0 回到顶端 [6 楼] From:香港没有资料 | Posted:2024-06-28 16:36 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.027111 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言