I'm working in a language called Sedona that can take native C methods. In order to integrate C in sedona, the variable declarations are a bit off.
- Sedona -> C
- bool -> int32_t
- bool[] -> uint8_t*
- byte -> int32_t
- byte[] -> uint8_t*
- short -> int32_t
- short[] -> uint16_t*
- int -> int32_t
- int[] -> int32_t*
- long -> int64_t
- long[] -> int64_t*
- float -> float
- float[] -> float*
- double -> double
- double[] -> double*
- Obj -> void*
- Obj[] -> void**
- Str -> uint8_t*
- Str[] -> uint8_t**
My method is trying to open a file, read its contents and return the contents of the file as a string for the other Sedona method to use. I know most of you probably don't know Sedona, but I am getting some errors that I don't understand. Here is my code:
#include <stdio.h>
#include "sedona.h"
Cell MyWeblet_MainWeblet_getFile(SedonaVM* vm, Cell* params){
uint8_t* file_name = params[1].aval;
FILE *fp;
uint8_t* fileContents;
struct stat st;
stat(&file_name, &st);
int32_t size = st.st_size;
int32_t itter = 0;
Cell result;
fileContents = malloc(sizeof(char)*size);
fp = fopen(file_name, "r"); //read mode
if (fp==NULL){
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
unit8_t* ch;
while ((ch = fgetc(fp))!=EOF){
fileContents[itter] = ch;
itter++;
}
result.aval = fileContents;
fclose(fp);
return result;
}
I'm getting more errors than this, but here is an example of what pops up:
- warning C4047:'function' : 'const char *' differs in levels of indirection from 'uint8_t **'
- warning C4024:'stat' : different types for formal and actual parameter 1
- error C2275: 'int32_t' : illegal use of this type as an expression
I really just want to understand what those errors mean, I don't need anyone to fix the code for me (although suggestions would be nice).