Robots/Wren: Difference between revisions
m
Minor tidy
(Added code.) |
m (Minor tidy) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1:
===Code===
{{trans|Go}}
{{libheader|ncurses}}
{{libheader|Wren-dynamic}}
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
{{works with|Ubuntu 20.04}}
An embedded script so we can use the ncurses library.
<
import "./dynamic" for Struct
Line 14 ⟶ 17:
class NC {
foreign static initScr()
foreign static useDefaultColors()
foreign static startColor()
Line 222 ⟶ 226:
var play = Fn.new {
NC.initScr()
NC.useDefaultColors()
NC.startColor()
for (i in 0...colors.count) {
NC.initPair(i+1, colors[i],
NC.initPair(i+11, colors[i], 2)
}
Line 293 ⟶ 298:
NC.echo()
NC.endwin()
NC.cursSet(1)</
<br>
We now embed this in the following C program, build and run it.
<
#include <stdio.h>
Line 309 ⟶ 314:
void C_initScr(WrenVM* vm) {
initscr();
}
void C_useDefaultColors(WrenVM* vm) {
use_default_colors();
}
Line 412 ⟶ 421:
if (strcmp(module, "main") == 0) {
if (strcmp(className, "NC") == 0) {
if (isStatic && strcmp(signature, "initScr()") == 0) return C_initScr;
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "
if (isStatic && strcmp(signature, "endwin()") == 0) return C_endwin;
}
}
Line 488 ⟶ 498:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 509 ⟶ 519:
free(script);
return 0;
}</
|