Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
\ tell 8th what the function expects:
|
||||
"ZZ" "strdup" func: strdup
|
||||
"VZ" "free" func: free
|
||||
\ call the external funcs
|
||||
"abc" dup \ now we have two strings "abc" on the stack
|
||||
strdup .s cr \ after strdup, you'll have the new (but duplicate) string on the stack
|
||||
\ the ".s" will show both strings and you can see they are different items on the stack
|
||||
free \ let the c library free the string
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
'Using StrDup function in Shlwapi.dll
|
||||
Dim As Any Ptr library = DyLibLoad("Shlwapi")
|
||||
Dim strdup As Function (ByVal As Const ZString Ptr) As ZString Ptr
|
||||
strdup = DyLibSymbol(library, "StrDupA")
|
||||
|
||||
'Using LocalFree function in kernel32.dll
|
||||
Dim As Any Ptr library2 = DyLibLoad("kernel32")
|
||||
Dim localfree As Function (ByVal As Any Ptr) As Any Ptr
|
||||
localfree = DyLibSymbol(library2, "LocalFree")
|
||||
|
||||
Dim As ZString * 10 z = "duplicate" '' 10 characters including final zero byte
|
||||
Dim As Zstring Ptr pcz = strdup(@z) '' pointer to the duplicate string
|
||||
Print *pcz '' print duplicate string by dereferencing pointer
|
||||
localfree(pcz) '' free the memory which StrDup allocated internally
|
||||
pcz = 0 '' set pointer to null
|
||||
DyLibFree(library) '' unload first dll
|
||||
DyLibFree(library2) '' unload second fll
|
||||
End
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import "stdio.h";;
|
||||
import "string.h";;
|
||||
|
||||
let s1:string = "Hello World!";;
|
||||
let s2:char* = strdup(cstring(s1));;
|
||||
puts(s2);;
|
||||
free(s2 as void*)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
|
||||
echo strcmp("abc", "def")
|
||||
echo strcmp("hello", "hello")
|
||||
|
||||
proc printf(formatstr: cstring) {.header: "<stdio.h>", varargs.}
|
||||
|
||||
var x = "foo"
|
||||
printf("Hello %d %s!\n", 12, x)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
constant shlwapi = open_dll("shlwapi.dll")
|
||||
constant xStrDup = define_c_func(shlwapi,"StrDupA",{C_PTR},C_PTR)
|
||||
constant kernel32 = open_dll("kernel32.dll")
|
||||
constant xLocalFree = define_c_func(kernel32,"LocalFree",{C_PTR},C_PTR)
|
||||
constant HelloWorld = "Hello World!"
|
||||
|
||||
atom pMem = c_func(xStrDup,{HelloWorld})
|
||||
?peek_string(pMem)
|
||||
if c_func(xLocalFree,{pMem})!=NULL then ?9/0 end if
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import Foundation
|
||||
|
||||
let hello = "Hello, World!"
|
||||
let fromC = strdup(hello)
|
||||
let backToSwiftString = String.fromCString(fromC)
|
||||
Loading…
Add table
Add a link
Reference in a new issue