Call a foreign-language function: Difference between revisions

Content added Content deleted
(→‎{{header|Lisaac}}: Explain backtick notation)
Line 76: Line 76:


=={{header|Lisaac}}==
=={{header|Lisaac}}==
Use backtick notation (`...`) for referencing foreign language (C) features.
<lang Lisaac>
<lang Lisaac>
Section Header
Section Header
Line 81: Line 82:
+ name := TEST_C_INTERFACE;
+ name := TEST_C_INTERFACE;


// this will be inserted in front of the program
- external := `#include <string.h>`;
- external := `#include <string.h>`;


Line 91: Line 93:
s := "Hello World!";
s := "Hello World!";
p := s.to_external;
p := s.to_external;
// this will be inserted in-place
// use `expr`:type to tell Lisaac what's the type of the external expression
p := `strdup(@p)` : NATIVE_ARRAY[CHARACTER];
p := `strdup(@p)` : NATIVE_ARRAY[CHARACTER];
s.print;
s.print;
'='.print;
'='.print;
p.println;
p.println;
// this will also be inserted in-place, expression type disregarded
`free(@p)`;
`free(@p)`;
);
);