Created
October 29, 2009 11:53
-
-
Save axgle/221380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi-inliner' | |
module C | |
extend Inliner | |
inline do |b| | |
b.c_raw '#include <stdio.h> | |
#include <string.h> | |
' | |
end | |
inline ' | |
int main(){ | |
char s[255]; | |
gets(s); | |
printf("%s=%d\n",s,strlen(s)); | |
} | |
' | |
end | |
C.main | |
========'len' must in "inline',not in c_raw ========= | |
require 'ffi-inliner' | |
module C | |
extend Inliner | |
inline do |b| | |
b.c_raw %{ | |
#include <stdio.h> | |
#include <string.h> | |
} | |
end | |
inline %{ | |
int len(char *s){ | |
puts("len:"); | |
int i=0; | |
for(i=0;s[i]!='\0';i++); | |
return i; | |
} | |
} | |
inline ' | |
int main(){ | |
char s[255]; | |
gets(s); | |
printf("%s=%d\n",s,len(s)); | |
} | |
' | |
end | |
C.main | |
=====love.c========= | |
require 'ffi-inliner' | |
module C | |
extend Inliner | |
inline do |b| | |
b.c_raw %{ | |
#include <stdio.h> | |
#include <string.h> | |
} | |
end | |
inline %{ | |
int swap(char *a, char *b){ | |
char t[255]; | |
strcpy(t,a); | |
strcpy(a,b); | |
strcpy(b,t); | |
} | |
} | |
inline ' | |
int main(){ | |
char a[255]="love",b[255]="c"; | |
swap(a,b); | |
printf("%s:%s\n",a,b); | |
} | |
' | |
end | |
C.main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment