On Fri, 26 Jan 2007 14:19:27 -0500, Slava Pestov wrote > On 26-Jan-07, at 1:54 PM, bbrown wrote: > > > Hello, Factor talk; > > > > I am trying to use the alien interface and how to pass parameters > > to the C > > function calls. > > > > Here are my C functions (mysql) > > > > FUNCTION: MYSQL* mysql_init ( MYSQL* mysql ) ; > > FUNCTION: MYSQL* mysql_real_connect(MYSQL* mysql, char* host, > > char* user, > > char* passwd, char* db, int port, char* unix_socket, long > > clientflag ) ; > > > > The Factor code: > > > > : init-mysql ( -- conn ) > > f mysql_init ; > > > > I am having an issue with the word definition below, getting the right > > parameters to the C function call. > > > > : connect-mysql ( host user passwd db port -- ) > > #! Now, hard code the rest of the parameters > > #! How do I set it up to have the values above, the hard-coded > > values, > > #! passed to the 'mysql_real_connect' function > >> r init-mysql r> swap f 0 mysql_real_connect ; > > > > The error is basically saying that I am passing a fixnum when it > > expects a > > string, etc. > > Well presumably, the MYSQL* handle should come first, so you have to > do > > : connect-mysql > >r >r >r >r >r init-mysql r> r> r> r> r> f 0 ; > > But this is awkward. A better way is to have a tuple which you can > construct and pass around to various words: > > TUPLE: connection mysql host user password db port handle ; > > C: connection ( host user password db port -- connection ) > [ set-connection-port ] keep > [ set-connection-db ] keep > [ set-connection-password ] keep > [ set-connection-user ] keep > [ set-connection-host ] keep ; > > : open-connection ( connection -- ) > init-mysql swap > [ set-connection-mysql ] 2keep > [ connection-host ] keep > [ connection-user ] keep > [ connection-password ] keep > [ connection-db ] keep > [ connection-port f 0 mysql_real_connect ] keep > [ set-connection-handle ] keep ; > > : close-connection ( connection -- ) > ... ; > > ie, store all related info in one tuple, and write words which take > this tuple, instead of passing tons of arbitrary parameters around. > > Slava > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your opinions on IT & business topics through brief surveys - > and earn cash http://www.techsay.com/default.php? page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Factor-talk mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/factor-talk
No wonder I was having trouble with it. Thanks will look at that. -- Berlin Brown berlin dot brown at gmail dot com or bbrown at botspiritcompany dot com ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
