-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.c
96 lines (81 loc) · 2.7 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
*
* MIT License
*
* Copyright (c) 2023-2024 erysdren (it/she)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
******************************************************************************/
/*
* headers
*/
/* std */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* qcvm */
#include "qcvm.h"
/* qclib */
#include "qclib.h"
/* main */
int main(int argc, char **argv)
{
/* variables */
qcvm_t *qcvm;
int qcvm_field_field1;
int qcvm_field_field2;
int qcvm_entity_gtest;
int qcvm_global_gtest;
float field1;
const char *field2;
/* load qcvm */
qcvm = qcvm_from_file("test.dat");
/* check validity */
if (qcvm == NULL)
{
fprintf(stderr, "failed to load test.dat\n");
return 1;
}
else
{
fprintf(stdout, "test.dat successfully loaded\n");
}
/* install qclib */
qclib_install(qcvm);
/* entity fields test */
qcvm_field_field1 = qcvm_find_field(qcvm, "field1");
qcvm_field_field2 = qcvm_find_field(qcvm, "field2");
qcvm_global_gtest = qcvm_find_global(qcvm, "gtest");
qcvm_set_global_entity(qcvm, qcvm_global_gtest, qcvm_add_entity(qcvm));
qcvm_entity_gtest = qcvm_get_global_entity(qcvm, qcvm_global_gtest);
/* run function test() */
qcvm_run(qcvm, qcvm_find_function(qcvm, "test"));
field1 = qcvm_get_field_float(qcvm, qcvm_entity_gtest, qcvm_field_field1);
field2 = qcvm_get_field_string(qcvm, qcvm_entity_gtest, qcvm_field_field2);
/* print field2 string */
printf("gtest.field1 = %0.0f\n", field1);
printf("gtest.field2 = %s\n", field2);
/* dump qclib exports */
qcvm_dump_exports(qcvm, "../qclib/qclib.qc");
/* close qcvm */
qcvm_free(qcvm);
/* return success */
return 0;
}