当我研究Trying to create NSDecimal in iPhone-Wax面临的问题时,我现在的目标要低得多。如何在Wax中创建功能齐全的NSDecimalNumber?
我在新鲜蜡项目的AppDelegate.lua顶部添加了以下两行。
local x = NSDecimalNumber:initWithString("2.3")
print(x)
print(x:class())
输出
(0x631e054 => 0x631d1a0) 2.3
(0x631e924 => 0x25f618) NSCFNumber
而不是
(0x621e834 => 0x620c550) <NSDecimalNumber: 0x620c550>
启用完整日志记录会在调试窗口中显示以下跟踪:
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)
:
:
此日志中有两件事我没有要求,NSDecimalNumberPlaceholder和NSCFNumber。我相信这些是我悲伤的根源,我不知道它们来自哪里。关于如何解决问题的任何想法?
最终我想调用方法decimalValue,但是蜡抱怨它不能在数字上调用方法。
答案 0 :(得分:2)
NSDecimalNumber会覆盖-description
以返回它所代表的数字。当您正在记录语句打印“2.3”时,它实际上是打印NSDecimalNumber对象。您可以通过在-class
值上调用x
并打印它来自行验证。