Boxing/Unboxing Functions

Monkey Forums/Monkey Programming/Boxing/Unboxing Functions

Samah(Posted 2012) [#1]
Is it possible to get the Box/Unbox functions moved from reflection to lang? I'd like to be able to use them without having to import reflection. Setting REFLECTION_FILTER="" isn't really a solution, imo.


marksibly(Posted 2012) [#2]
Hi,

Sounds good to me - have you tried it?


Samah(Posted 2012) [#3]
No imports:

[monkeycode]Strict
Function Main:Int()
BoxInt(1)
Return 0
End[/monkeycode]
Error : Identifier 'BoxInt' not found.

[monkeycode]Strict
#REFLECTION_FILTER=""
Import reflection
Function Main:Int()
BoxInt(1)
Return 0
End[/monkeycode]
Works, but it seems a bit silly.

Edit: No, I haven't tried moving it there yet, but I don't see why it shouldn't work. Maybe Box/UnboxArray might break? I'll check it in a bit.

Edit 2: I see there is no Box/UnboxArray, and you need to use ArrayBoxer<T>.Box/Unbox, which needs reflection. Given that array boxing is fairly uncommon, I think it's probably OK to move the rest of them to lang.monkey, but leave ArrayBoxer in reflection.monkey.


marksibly(Posted 2012) [#4]
Hi,

Just did a quick cut/paste test and it seems to work OK, including ArrayBoxer.

Haven't tested reflection though - have you got some reasonably serious reflection code to thrash it with, eg: the Lua stuff?


Samah(Posted 2012) [#5]
I haven't quite finished the pure Monkey port of Lua yet, since I need to rewrite some of the syntax parsing stuff to not use Java streams. I can't guarantee this Lua VM is going to be particularly fast either... ;)

I can probably come up with something to break it, I'm good at that. ;D