Important change : Well, I'm stupid (and looking for complex answers to simple questions). A quick read of the Wax blog and I find https://github.com/probablycorey/wax/wiki/Overview which mentions the toobjc function. So it looks like ...
local x = (toobjc)(NDecimalNumber:initWithString("2.3"));
will do what you want (i.e. prevent automatic conversion of type Lua). Maybe my syntax is a little wrong, so experiment. I lost my original answer below to illustrate another βsolutionβ.
So, looking at the wax (which I don't know very well), one key act that it performs when binding Objective-C and Lua is to convert all Objective-C types to their corresponding native Lua types. This includes NSNumber types (such as NSDecimal ) that map to Lua number types.
Of course, you already know this, therefore, your changes to wax-helpers.m . Alas, what you have done is not enough. Conversions still occur, and therefore, your NSDecimalNumber is still becoming a number. It looks like depending on whether it is used in your Lua code, Lua explodes (trying to index the scalar type), or the Objective-C bridge explodes. I'm not sure why you sometimes get a Lua trace error (if your code is always identical); this indicates some basic assumptions about the violation of the internal state of the wax.
A better solution would be one that does not require a wax change. At this point, even if the βfixβ does work, you have completely disabled automatic coercion between types. This, I think, will break a lot of wax codes and idioms. Looking at Wax, it will only perform automatic conversions for types that are subclasses of some Foundation classes that it specifically understands; any type of object that he does not know about remains an object. In this case, we got into the conversion of NSValue and NSNumber , so my first suggestion is to simply wrap NSDecimalNumber in some class that Wax does not understand. Sort of...
@interface MyDecimalWrapper : NSObject { NSDecimalValue *myDecimal; } - (NSDecimalValue*)getDecimalValue; - (NSDecimal*)getDecimal; @end @implementation MyDecimalWrapper - (NSDecimalValue*)getDecimalValue { return [[myDecimal retain] autorelease] } - (NSDecimal*)getDecimal { return [myDecimal decimalValue]; } @end
This can be added to Wax without significant code changes, and using it to port NSDecimalValue across the bridge should prevent Wax type conversion. Of course, if you use getDecimalValue inside Lua, the result will be quickly wrapped in a Lua number . If you need to call methods in the base NSDecimalValue in Lua, simply proxy them from the equivalent methods defined on the wrapper.
If this doesn't work for you at all, I can probably change the changes necessary for Wax. But it will be a world of pain supporting your own port, and a breakdown of many existing wax codes and examples.
Tangentially: I'm not sure what you intend to do with NSDecimal when you have one in Lua. This is an opaque C structure that can only be used through the C interface provided by Foundation.