浏览代码

Merge branch 'master' of https://github.com/raysan5/raylib

pull/2131/head
Ray 3 年前
父节点
当前提交
2c38dad214
共有 6 个文件被更改,包括 6951 次插入22 次删除
  1. +3
    -0
      .gitignore
  2. +1
    -0
      BINDINGS.md
  3. +27
    -0
      parser/Makefile
  4. +6816
    -0
      parser/raylib_api.lua
  5. +87
    -2
      parser/raylib_parser.c
  6. +17
    -20
      src/rcore.c

+ 3
- 0
.gitignore 查看文件

@ -101,3 +101,6 @@ zig-out/
build/
build-*/
docgen_tmp/
# Parser stuff
parser/raylib_parser

+ 1
- 0
BINDINGS.md 查看文件

@ -42,6 +42,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to
| kaylib | 3.7 | [Kotlin/native](https://kotlinlang.org) | https://github.com/electronstudio/kaylib |
| dlang_raylib | 3.7 | [D](https://dlang.org) | https://github.com/rc-05/dlang_raylib |
| raylib-freebasic | **4.0** | [FreeBASIC](https://www.freebasic.net/) | https://github.com/WIITD/raylib-freebasic |
| raylib-cr | **4.0** | [Crystal](https://crystal-lang.org/) | https://github.com/sol-vin/raylib-cr |
### Utility Wrapers
These are utility wrappers for specific languages, they are not required to use raylib in the language but may adapt the raylib API to be more inline with the language's pardigm.

+ 27
- 0
parser/Makefile 查看文件

@ -0,0 +1,27 @@
EXTENSION?=txt
FORMAT?=DEFAULT
raylib_api:
cc raylib_parser.c -o raylib_parser
./raylib_parser -i ../src/raylib.h -o raylib_api.txt -f DEFAULT -d RLAPI
./raylib_parser -i ../src/raylib.h -o raylib_api.json -f JSON -d RLAPI
./raylib_parser -i ../src/raylib.h -o raylib_api.xml -f XML -d RLAPI
./raylib_parser -i ../src/raylib.h -o raylib_api.lua -f LUA -d RLAPI
all:
cc raylib_parser.c -o raylib_parser
FORMAT=DEFAULT EXTENSION=txt $(MAKE) parse
FORMAT=JSON EXTENSION=json $(MAKE) parse
FORMAT=XML EXTENSION=xml $(MAKE) parse
FORMAT=LUA EXTENSION=lua $(MAKE) parse
parse:
./raylib_parser -i ../src/raylib.h -o raylib_api.$(EXTENSION) -f $(FORMAT) -d RLAPI
./raylib_parser -i ../src/raymath.h -o raymath_api.$(EXTENSION) -f $(FORMAT) -d RMAPI
./raylib_parser -i ../src/extras/easings.h -o easings_api.$(EXTENSION) -f $(FORMAT) -d EASEDEF
./raylib_parser -i ../src/extras/physac.h -o physac_api.$(EXTENSION) -f $(FORMAT) -d PHYSACDEF
./raylib_parser -i ../src/extras/raygui.h -o raygui_api.$(EXTENSION) -f $(FORMAT) -d RAYGUIDEF
./raylib_parser -i ../src/extras/rmem.h -o rmem_api.$(EXTENSION) -f $(FORMAT) -d RMEMAPI
clean:
rm -f raylib_parser *.json *.txt *.xml *.lua

+ 6816
- 0
parser/raylib_api.lua
文件差异内容过多而无法显示
查看文件


+ 87
- 2
parser/raylib_parser.c 查看文件

@ -109,7 +109,7 @@ typedef struct EnumInfo {
} EnumInfo;
// Output format for parsed data
typedef enum { DEFAULT = 0, JSON, XML } OutputFormat;
typedef enum { DEFAULT = 0, JSON, XML, LUA } OutputFormat;
//----------------------------------------------------------------------------------
// Global Variables Definition
@ -500,6 +500,7 @@ int main(int argc, char* argv[])
if (outputFormat == DEFAULT) printf("\nOutput format: DEFAULT\n\n");
else if (outputFormat == JSON) printf("\nOutput format: JSON\n\n");
else if (outputFormat == XML) printf("\nOutput format: XML\n\n");
else if (outputFormat == LUA) printf("\nOutput format: LUA\n\n");
ExportParsedData(outFileName, outputFormat);
@ -535,7 +536,7 @@ static void ShowCommandLineInfo(void)
printf(" Supported extensions: .txt, .json, .xml, .h\n");
printf(" NOTE: If not specified, defaults to: raylib_api.txt\n\n");
printf(" -f, --format <type> : Define output format for parser data.\n");
printf(" Supported types: DEFAULT, JSON, XML\n\n");
printf(" Supported types: DEFAULT, JSON, XML, LUA\n\n");
printf(" -d, --define <DEF> : Define functions define (i.e. RLAPI for raylib.h, RMDEF for raymath.h, etc\n");
printf(" NOTE: If not specified, defaults to: RLAPI\n\n");
@ -584,6 +585,7 @@ static void ProcessCommandLine(int argc, char *argv[])
if (IsTextEqual(argv[i + 1], "DEFAULT\0", 8)) outputFormat = DEFAULT;
else if (IsTextEqual(argv[i + 1], "JSON\0", 5)) outputFormat = JSON;
else if (IsTextEqual(argv[i + 1], "XML\0", 4)) outputFormat = XML;
else if (IsTextEqual(argv[i + 1], "LUA\0", 4)) outputFormat = LUA;
}
else printf("WARNING: No format parameters provided\n");
}
@ -841,6 +843,89 @@ static void ExportParsedData(const char *fileName, int format)
if (funcs[i].paramCount == 0) fprintf(outFile, " No input parameters\n");
}
} break;
case LUA:
{
fprintf(outFile, "return {\n");
// Print structs info
fprintf(outFile, " structs = {\n");
for (int i = 0; i < structCount; i++)
{
fprintf(outFile, " {\n");
fprintf(outFile, " name = \"%s\",\n", structs[i].name);
fprintf(outFile, " description = \"%s\",\n", structs[i].desc);
fprintf(outFile, " fields = {\n");
for (int f = 0; f < structs[i].fieldCount; f++)
{
fprintf(outFile, " {\n");
fprintf(outFile, " name = \"%s\",\n", structs[i].fieldName[f]),
fprintf(outFile, " type = \"%s\",\n", structs[i].fieldType[f]),
fprintf(outFile, " description = \"%s\"\n", structs[i].fieldDesc[f] + 3),
fprintf(outFile, " }");
if (f < structs[i].fieldCount - 1) fprintf(outFile, ",\n");
else fprintf(outFile, "\n");
}
fprintf(outFile, " }\n");
fprintf(outFile, " }");
if (i < structCount - 1) fprintf(outFile, ",\n");
else fprintf(outFile, "\n");
}
fprintf(outFile, " },\n");
// Print enums info
fprintf(outFile, " enums = {\n");
for (int i = 0; i < enumCount; i++)
{
fprintf(outFile, " {\n");
fprintf(outFile, " name = \"%s\",\n", enums[i].name);
fprintf(outFile, " description = \"%s\",\n", enums[i].desc + 3);
fprintf(outFile, " values = {\n");
for (int e = 0; e < enums[i].valueCount; e++)
{
fprintf(outFile, " {\n");
fprintf(outFile, " name = \"%s\",\n", enums[i].valueName[e]),
fprintf(outFile, " value = %i,\n", enums[i].valueInteger[e]),
fprintf(outFile, " description = \"%s\"\n", enums[i].valueDesc[e] + 3),
fprintf(outFile, " }");
if (e < enums[i].valueCount - 1) fprintf(outFile, ",\n");
else fprintf(outFile, "\n");
}
fprintf(outFile, " }\n");
fprintf(outFile, " }");
if (i < enumCount - 1) fprintf(outFile, ",\n");
else fprintf(outFile, "\n");
}
fprintf(outFile, " },\n");
// Print functions info
fprintf(outFile, " functions = {\n");
for (int i = 0; i < funcCount; i++)
{
fprintf(outFile, " {\n");
fprintf(outFile, " name = \"%s\",\n", funcs[i].name);
fprintf(outFile, " description = \"%s\",\n", CharReplace(funcs[i].desc, '\\', ' ') + 3);
fprintf(outFile, " returnType = \"%s\"", funcs[i].retType);
if (funcs[i].paramCount == 0) fprintf(outFile, "\n");
else
{
fprintf(outFile, ",\n params = {\n");
for (int p = 0; p < funcs[i].paramCount; p++)
{
fprintf(outFile, " {name = \"%s\", type = \"%s\"}", funcs[i].paramName[p], funcs[i].paramType[p]);
if (p < funcs[i].paramCount - 1) fprintf(outFile, ",\n");
else fprintf(outFile, "\n");
}
fprintf(outFile, " }\n");
}
fprintf(outFile, " }");
if (i < funcCount - 1) fprintf(outFile, ",\n");
else fprintf(outFile, "\n");
}
fprintf(outFile, " }\n");
fprintf(outFile, "}\n");
} break;
case JSON:
{
fprintf(outFile, "{\n");

+ 17
- 20
src/rcore.c 查看文件

@ -2894,41 +2894,38 @@ const char *GetWorkingDirectory(void)
return path;
}
// Get filenames in a directory path (max 512 files)
// Get filenames in a directory path
// NOTE: Files count is returned by parameters pointer
char **GetDirectoryFiles(const char *dirPath, int *fileCount)
{
#define MAX_DIRECTORY_FILES 512
ClearDirectoryFiles();
// Memory allocation for MAX_DIRECTORY_FILES
dirFilesPath = (char **)RL_MALLOC(MAX_DIRECTORY_FILES*sizeof(char *));
for (int i = 0; i < MAX_DIRECTORY_FILES; i++) dirFilesPath[i] = (char *)RL_MALLOC(MAX_FILEPATH_LENGTH*sizeof(char));
int counter = 0;
struct dirent *entity;
DIR *dir = opendir(dirPath);
if (dir != NULL) // It's a directory
if (dir != NULL) // It's a directory
{
// TODO: Reading could be done in two passes,
// first one to count files and second one to read names
// That way we can allocate required memory, instead of a limited pool
// Count files
while ((entity = readdir(dir)) != NULL) counter++;
while ((entity = readdir(dir)) != NULL)
{
strcpy(dirFilesPath[counter], entity->d_name);
counter++;
}
dirFileCount = counter;
*fileCount = dirFileCount;
// Memory allocation for dirFileCount
dirFilesPath = (char **)RL_MALLOC(dirFileCount*sizeof(char *));
for (int i = 0; i < dirFileCount; i++) dirFilesPath[i] = (char *)RL_MALLOC(MAX_FILEPATH_LENGTH*sizeof(char));
// Reset our position in the directory to the beginning
rewinddir(dir);
// Read file names
for (int i = 0; (entity = readdir(dir)) != NULL; i++) strcpy(dirFilesPath[i], entity->d_name);
closedir(dir);
}
else TRACELOG(LOG_WARNING, "FILEIO: Failed to open requested directory"); // Maybe it's a file...
dirFileCount = counter;
*fileCount = dirFileCount;
return dirFilesPath;
}
@ -2937,7 +2934,7 @@ void ClearDirectoryFiles(void)
{
if (dirFileCount > 0)
{
for (int i = 0; i < MAX_DIRECTORY_FILES; i++) RL_FREE(dirFilesPath[i]);
for (int i = 0; i < dirFileCount; i++) RL_FREE(dirFilesPath[i]);
RL_FREE(dirFilesPath);
}

正在加载...
取消
保存