如何在 XS 中编写 Perl 构造函数?
我正在尝试为 Perl 编写新的 XS 模块。我已经按照 XS 模块编写指令进行了测试,并且工作正常。
我无法理解如何为 XS 编写 new
方法,
我有一个名为 Agent
的包。我希望能够做到这样的事情:
my $agent_object = new Agent;
I am trying to write new XS module for Perl. I have tested by following XS module writing instruction and it is working fine.
I am not able to understand how to I write new
method for XS
I have a package called Agent
. I want to be able to something like this:
my $agent_object = new Agent;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我从 XS Mechanics 得到了答案。
感谢您的帮助
I got the answer from XS Mechanics.
Thanks For your help
以下代码实现了
XS 中的典型构造函数。它是从 Class::XSAccessor 逐字复制的。我建议您在使用普通的基于哈希的对象时调查 Class::XSAccessor 的情况。无需重新发明这个轮子。
The following code implements a typical
constructor in XS. It's copied verbatim from Class::XSAccessor. I would suggest you investigate Class::XSAccessor for cases when you are using an ordinary hash based object. No need to reinvent this wheel.
如果您的 Agent.xs 包含:
当您说 Agent->new 时,XS 不会自动调用该构造函数吗?
If your Agent.xs contains:
doesn't XS call that constructor automatically when you say Agent->new?