My favorites | Sign in
Project Home Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 37: FFI should auto-cast pointer types when possible
1 person starred this issue and may be notified of changes. Back to list
Status:  Accepted

Sign in to add a comment
Project Member Reported by, Jan 27, 2010
Currently, we have to do this

const _getpwnam = new ffi.CFunction(ffi.pointer, "getpwnam", ffi.pointer);
var pwent ="wes");
pwent = ffi.MutableStruct("struct pwent", pwent);
print("Your home directory is " + pwent.pw_dir);

It would be nice to collapse that to

const _getpwnam = new ffi.CFunction(ffi.MutableStruct("struct pwent"),
"getpwnam", ffi.pointer);
print("Your home directory is " +"wes").pw_dir);

We can accomplish that like so:

 - All ByteThing casters are of the form Caster(X, Y), where X is a series
of 0 or more specifying arguments and Y is a ByteThing
 - When we call Caster(X) it returns a closure which takes a single argument
 - This closure, when invoked as CasterXClosure(Y) returns the equivalent
of Caster(X,Y)
 - The CFunction constructor will treat a return type-indicator which
happens to be a closure as though it were ffi.pointer
 - When the constructed CFunction is invoked with call, the boxing code
will box up CasterXClosure(Y) instead of Y
Sep 5, 2012
Project Member #1
(No comment was entered for this change.)
Sign in to add a comment

Powered by Google Project Hosting