0

当我研究我在尝试在 iPhone-Wax 中创建 NSDecimal时遇到的问题时,我现在的目标要低得多。如何在 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,但蜡抱怨它不能调用一个数字的方法。

4

1 回答 1

2

NSDecimalNumber 覆盖-description以返回它所代表的数字。当您记录语句正在打印“2.3”时,它实际上是在打印 NSDecimalNumber 对象。您可以通过调用-class您的x值并打印出来自己验证这一点。

于 2011-06-26T03:04:20.273 回答