lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 9 Nov 2015 2:00 pm, "Dibyendu Majumdar" <mobile@majumdar.org.uk> wrote:
>
> Hi,
>
> As I progress with Ravi I often wish there was a way to perform type
> assertion or coercion in the language. For example:
>
> local t = { 1 }
> local i: integer = t[1]
>
> Above fails in Ravi as the compiler cannot know that the value
> returned from t[1] is an integer.
>
> It would be nice to be able to say:
>
> local i: integer = t[1] as integer
>
> Or some such like.
>
> Language support is essential for performance reasons; Ravi already
> supports type coercion of function return values. So following already
> works.
>
> function asinteger(a) return a end
> local i: integer = asinteger(t[1])
>
> Problem is this is bad for performance.
>
> Now here is a hypothetical question - if Lua had been statically typed
> language - what would the ideal _expression_ be for this kind of type
> coercion?
>
> Regards
> Dibyendu
>

Have you seen typedlua? https://github.com/andremm/typedlua