问题描述
当我研究我在我现在的目标低得多。如何在Wax中创建一个完全功能的NSDecimalNumber?
我在AppDelegate.lua的顶部在一个新的蜡项目中添加了以下两行。
local x = NSDecimalNumber:initWithString(2.3)
print(x)
print )
输出为
(0x631e054 => 0x631d1a0)2.3
(0x631e924 => 0x25f618)NSCFNumber
b $ b
而不是像
(0x621e834 => 0x620c550)< NSDecimalNumber:0x620c550&
打开完整日志记录,在调试窗口中提供以下跟踪:
为WaxServer创建类(0x621bf40)
将引用存储到userdata表WaxServer(0x621bf40 - > 0x621c454)
存储引用到强用户数据表WaxServer(0x621bf40 - > 0x621c454)
为NSDecimalNumber(0x261120)创建类
将类引用存储到userdata表NSDecimalNumber(0x261120 - > 0x6205e44)
存储引用到strong userdata table NSDecimalNumber(0x261120 - > 0x6205e44)
为NSDecimalNumberPlaceholder创建实例(0x6213450)
为NSDecimalNumberPlaceholder保留实例(0x6213450 - > 0x621d7c4)
将实例引用存储到userdata表NSDecimalNumberPlaceholder(0x6213450 - > 0x621d7c4)
存储对强用户数据表的引用NSDecimalNumberPlaceholder(0x6213450 - > 0x621d7c4)
为NSCFNumber创建实例(0x620c550)
保留NSCFNumber的实例(0x620c550 - > 0x621e834)
将实例的引用存储到userdata表NSCFNumber(0x620c550 - > 0x621e834)
存储对strong userdata表的引用NSCFNumber(0x620c550 - > 0x621e834)
(0x621e834 => 0x620c550) 2.3
为AppDelegate创建类(0x621ec50)
:
:
两个东西都显示在这个日志中,我没有要求,NSDecimalNumberPlaceholder和NSCFNumber。我相信这些是我悲伤的根源,我不知道他们来自哪里。关于如何解决这个问题的任何想法?
最后,我想调用的方法decimalValue,但蜡抱怨,它不能调用一个数字上的方法。 p>
NSDecimalNumber覆盖 -description
,返回它所代表的数字。当你日志语句正在打印2.3时,它实际上是打印NSDecimalNumber对象。您可以通过在 x
值上调用 -class
并打印该值来自行验证。
As I studied the issue I am facing in Trying to create NSDecimal in iPhone-Wax I am now aiming much lower. How can I create a fully functional NSDecimalNumber in Wax?
I have added the following two lines at the top of AppDelegate.lua in a fresh wax project.
local x = NSDecimalNumber:initWithString("2.3")
print(x)
print(x:class())
The output is
(0x631e054 => 0x631d1a0) 2.3
(0x631e924 => 0x25f618) NSCFNumber
instead of something like
(0x621e834 => 0x620c550) <NSDecimalNumber: 0x620c550>
Turning on full logging in wax give the following trace in the debug window:
Creating class for WaxServer(0x621bf40)
Storing reference of class to userdata table WaxServer(0x621bf40 -> 0x621c454)
Storing reference to strong userdata table WaxServer(0x621bf40 -> 0x621c454)
Creating class for NSDecimalNumber(0x261120)
Storing reference of class to userdata table NSDecimalNumber(0x261120 -> 0x6205e44)
Storing reference to strong userdata table NSDecimalNumber(0x261120 -> 0x6205e44)
Creating instance for NSDecimalNumberPlaceholder(0x6213450)
Retaining instance for NSDecimalNumberPlaceholder(0x6213450 -> 0x621d7c4)
Storing reference of instance to userdata table NSDecimalNumberPlaceholder(0x6213450 -> 0x621d7c4)
Storing reference to strong userdata table NSDecimalNumberPlaceholder(0x6213450 -> 0x621d7c4)
Creating instance for NSCFNumber(0x620c550)
Retaining instance for NSCFNumber(0x620c550 -> 0x621e834)
Storing reference of instance to userdata table NSCFNumber(0x620c550 -> 0x621e834)
Storing reference to strong userdata table NSCFNumber(0x620c550 -> 0x621e834)
(0x621e834 => 0x620c550) 2.3
Creating class for AppDelegate(0x621ec50)
:
:
Two things are showing in this log which I did not ask for, NSDecimalNumberPlaceholder and NSCFNumber. I believe these are the source of my grief and I have no idea where they are coming from. Any ideas on how to fix the issue?
Ultimately I want to call the method decimalValue, but wax complains that it can't call a method on a number.
NSDecimalNumber overrides -description
to return the number it represents. When you're logging statement is printing "2.3", it is in fact printing the NSDecimalNumber object. You can verify this for yourself by calling -class
on your x
value and printing that as well.
这篇关于试图在蜡中创建诚实的NSDecimalNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!