Lua Notes

odin any type
Login

odin any type

https://odin-lang.org/docs/overview/#any-type - "An any type can reference any data type. Internally it contains a pointer to the underlying data and its relevant typeid."

require 'traits'

local any = @record{id: uint32, data: pointer}
## local function to_any(x)
  in (@any){traits.typeidof(#[x]#), &#[x]#}
## end

local function show(x: any)
  if     x.id == traits.typeidof(number) then print($(@*number)(x.data))
  elseif x.id == traits.typeidof(string) then print($(@*string)(x.data))
  end
end

local x, y = 123_number, 'abc'
show(#[to_any]#(x))
show(#[to_any]#(y))