Skip to content

Value Conversion

qtiuto edited this page Jul 8, 2019 · 3 revisions

For field set and method call or proxy return,lua object will be converted automatically according to the type. Type check have the same rule in method deduction. If type check failed,an exception will be thrown.

To suggest the type you wish the value to be, you can add a type before the argument. This type is used for automatic value conversion and method deduction or object conversion for object method

For primitive types, the primitive value in its range and its associated box type are valid.

For char type, only one-character is acceptable,and return value will be converted to one-character string.

Object.class receives all values including primitive types.

Number.class receives all primitive types and its children.

For object types,no conversion.

For function,like call proxy with only one type and one function provided.

For table, if the table is convertible, it's converted by the table converter else it's like call proxy with super set to the type and methods set to the table if it's valid to be converted. Additionally, generic type check and conversion will be performed automatically, that's to say, 'Type' such as List,List or List<List> will be supported.

Actually, the table converter is a little bit inefficient cause it needs to store a lua table to a c++ vector and then to a java map and finally to the object specified. If you really care about efficiency, avoid using table auto cast.

Userdata is treated as integer.

Note:

  1. All primitive types accept their boxed types and all boxed types accept their primitive types. Auto-box and auto-unbox will be performed if necessary.
  2. If you want to perform a forced conversion to the primitive value, you can do this by wrapping the value to the type you wished is to be, e.g. local v=char(54);local k=int('g'). Forced Conversion is allowed from any primitive value to any other primitive type except for boolean type which only receives boolean value and its boxed type.

Clone this wiki locally