1
0
Fork 0
This commit is contained in:
Morgan 2024-03-21 03:34:07 +09:00
parent c1593c551c
commit 85d5641e54
No known key found for this signature in database
19 changed files with 84 additions and 0 deletions

0
buildmaybe.sh → container/buildmaybe.sh Executable file → Normal file
View File

1
glsl/ex0.c Normal file
View File

@ -0,0 +1 @@
// glsl?

BIN
test/ex0 Executable file

Binary file not shown.

48
test/ex0.c Normal file
View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <yaml.h>
int main(void) {
char yamlfile[2048] = {0};
printf("YAML file?");
scanf("%s", yamlfile);
FILE *fh = fopen(yamlfile, "r");
yaml_parser_t parser;
yaml_token_t token;
if (!yaml_parser_initialize(&parser)) {
fputs("Failed to initialize parser!\n", stderr);
}
if (fh == NULL) {
fputs("Failed to open file!\n", stderr);
}
yaml_parser_set_input_file(&parser, fh);
do {
yaml_parser_scan(&parser, &token);
switch(token.type) {
case YAML_KEY_TOKEN:
printf("Key: ");
break;
case YAML_VALUE_TOKEN:
printf("Value: ");
break;
case YAML_SCALAR_TOKEN:
printf("%s\n", token.data.scalar.value);
break;
default:
break;
}
if(token.type != YAML_STREAM_END_TOKEN)
yaml_token_delete(&token);
} while(token.type != YAML_STREAM_END_TOKEN);
yaml_token_delete(&token);
yaml_parser_delete(&parser);
fclose(fh);
return 0;
}

2
test/ex0.yaml Normal file
View File

@ -0,0 +1,2 @@
name: John Doe
age: 30

BIN
test/ex1 Executable file

Binary file not shown.

32
test/ex1.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int main() {
int val = 5;
printf("Original value: %d\n", val);
lua_State *L = luaL_newstate();
luaL_openlibs(L);
if (luaL_dofile(L, "ex1.lua") != LUA_OK) {
fprintf(stderr, "Could not load script: %s\n", lua_tostring(L, -1));
exit(1);
}
lua_getglobal(L, "value");
if (lua_isnumber(L, -1)) {
val = (int)lua_tonumber(L, -1);
} else {
fprintf(stderr, "Expected a number\n");
exit(1);
}
printf("Modified value: %d\n", val);
lua_close(L);
return 0;
}

1
test/ex1.lua Normal file
View File

@ -0,0 +1 @@
value = 10