1 #include "api_function.h"
2 #include <stdio.h>
3 
4 #include "../simsys.h"
5 
6 #include "../dataobj/environment.h"
7 
8 /**
9  * Auxiliary function to register function in table/class at stack top
10  */
register_function(HSQUIRRELVM vm,SQFUNCTION funcptr,const char * name,int nparamcheck,const char * typemask,bool staticmethod)11 void script_api::register_function(HSQUIRRELVM vm, SQFUNCTION funcptr, const char *name, int nparamcheck, const char* typemask, bool staticmethod)
12 {
13 	sq_pushstring(vm, name, -1);
14 	sq_newclosure(vm, funcptr, 0); //create a new function
15 	sq_setnativeclosurename(vm, -1, name);
16 	sq_setparamscheck(vm, nparamcheck, typemask);
17 	sq_newslot(vm, -3, staticmethod);
18 }
19 
20 static FILE* file = NULL;
21 
start_squirrel_type_logging(const char * suffix)22 void script_api::start_squirrel_type_logging(const char* suffix)
23 {
24 	if (env_t::verbose_debug < 2) {
25 		return;
26 	}
27 	cbuffer_t buf;
28 	buf.printf("squirrel_types_%s.awk", suffix);
29 	file = dr_fopen(buf, "w");
30 	if (file) {
31 		fprintf(file, "# file used to generate doxygen documentation of squirrel API\n");
32 		fprintf(file, "# needs to be copied to trunk/script/api\n");
33 		fprintf(file, "BEGIN {\n");
34 	}
35 }
36 
end_squirrel_type_logging()37 void script_api::end_squirrel_type_logging()
38 {
39 	if (file) {
40 		fprintf(file, "}\n");
41 		fclose(file);
42 		file = NULL;
43 	}
44 }
45 
46 static plainstring current_class;
47 
set_squirrel_type_class(const char * classname)48 void script_api::set_squirrel_type_class(const char* classname)
49 {
50 	current_class = classname;
51 }
52 
log_squirrel_type(std::string classname,const char * name,std::string squirrel_type)53 void script_api::log_squirrel_type(std::string classname, const char* name, std::string squirrel_type)
54 {
55 	if (file) {
56 		fprintf(file, "\texport_types[\"%s::%s\"] = \"%s\"\n",
57 			classname.compare(param<void_t>::squirrel_type()) == 0 ? current_class.c_str() : classname.c_str(),
58 			name,
59 			squirrel_type.c_str()
60 		);
61 	}
62 }
63