Trying to create honest NSDecimalNumber in Wax

爷,独闯天下 提交于 2019-12-12 06:23:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6481873/trying-to-create-honest-nsdecimalnumber-in-wax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!