Math ctype objects?

  • From: Alex <initrd.gz@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 20 Jan 2013 17:25:38 -0500

I typo'd one of my programs to multiply a ctype object by a number, and
wondered why my program wasn't throwing an error when it did so.

Apparently this is what happens:

LuaJIT 2.0.0 -- Copyright (C) 2005-2012 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
> ffi = require "ffi"
> int = ffi.typeof("int")
> print(int*3)
27LL
> float = ffi.typeof("float")
> print(float*1)
13LL

It looks like the other operators work too; you can even do
ffi.typeof("int")+ffi.typeof("float").
So I'm left wondering, is this a side effect of something or is this some
hidden feature? It's nothing major; I'm just curious.

Thanks, Alex

Other related posts: