开发者

Trying to create honest NSDecimalNumber in Wax

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 tab开发者_运维技巧le 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜