]> Nishi Git Mirror - serenade.git/commitdiff
source directive
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Sat, 27 Apr 2024 01:45:55 +0000 (01:45 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Sat, 27 Apr 2024 01:45:55 +0000 (01:45 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@65 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Serenade/ffi_binding.c

index e9758b5961b8f24717c4d7c1283bffdb1d7c9b54..bfa5dd017c96f5c6d532627f3d4e0e8ce65792e5 100644 (file)
@@ -93,6 +93,10 @@ struct sn_generic* function_caller_handler(struct sn_interpreter* sn, int args,
                                double* data = malloc(sizeof(double));
                                *data = gens[i + 1]->number;
                                ptr = data;
+                       } else if(strcmp(info->argtypes[i + 1], "float") == 0) {
+                               float* data = malloc(sizeof(float));
+                               *data = gens[i + 1]->number;
+                               ptr = data;
                        } else if(strcmp(info->argtypes[i + 1], "byte") == 0) {
                                char* data = malloc(sizeof(char));
                                *data = gens[i + 1]->number;
@@ -117,6 +121,9 @@ struct sn_generic* function_caller_handler(struct sn_interpreter* sn, int args,
        } else if(strcmp(info->argtypes[0], "double") == 0) {
                gen->type = SN_TYPE_DOUBLE;
                gen->number = *(double*)&result;
+       } else if(strcmp(info->argtypes[0], "float") == 0) {
+               gen->type = SN_TYPE_DOUBLE;
+               gen->number = *(float*)&result;
        } else if(strcmp(info->argtypes[0], "integer") == 0) {
                gen->type = SN_TYPE_DOUBLE;
                gen->number = *(int*)&result;
@@ -129,6 +136,12 @@ struct sn_generic* function_caller_handler(struct sn_interpreter* sn, int args,
                gen->string_length = strlen(gen->string);
        }
 
+       for(i = 0; fargs[i] != NULL; i++) {
+               if(strcmp(info->argtypes[i + 1], "string") == 0) {
+                       free(*((void**)fargs[i]));
+                       free(fargs[i]);
+               }
+       }
        if(fargs != NULL) free(fargs);
        return gen;
 }
@@ -169,6 +182,8 @@ struct sn_generic* ffi_function_handler(struct sn_interpreter* sn, int args, str
                                        assign = &ffi_type_pointer;
                                } else if(strcmp(typ, "byte") == 0) {
                                        assign = &ffi_type_schar;
+                               } else if(strcmp(typ, "float") == 0) {
+                                       assign = &ffi_type_float;
                                }
 
                                info->argtypes[i - 2] = typ;