feat: port lua scripting language

This commit is contained in:
2026-03-27 21:53:33 +01:00
parent 88ff98c325
commit d197665fdd
131 changed files with 46362 additions and 358 deletions
+31
View File
@@ -0,0 +1,31 @@
#ifndef _LIBC_DIRENT_H
#define _LIBC_DIRENT_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define NAME_MAX 255
#define DT_UNKNOWN 0
#define DT_DIR 4
#define DT_REG 8
struct dirent {
unsigned char d_type;
char d_name[NAME_MAX + 1];
};
typedef struct _DIR DIR;
DIR *opendir(const char *name);
struct dirent *readdir(DIR *dirp);
int closedir(DIR *dirp);
void rewinddir(DIR *dirp);
#ifdef __cplusplus
}
#endif
#endif /* _LIBC_DIRENT_H */
+28
View File
@@ -0,0 +1,28 @@
#ifndef _LIBC_LOCALE_H
#define _LIBC_LOCALE_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2
#define LC_MONETARY 3
#define LC_NUMERIC 4
#define LC_TIME 5
struct lconv {
char *decimal_point;
};
char *setlocale(int category, const char *locale);
struct lconv *localeconv(void);
#ifdef __cplusplus
}
#endif
#endif /* _LIBC_LOCALE_H */
+8
View File
@@ -12,12 +12,17 @@ extern "C" {
#define NAN __builtin_nanf("")
double fabs(double x);
double frexp(double x, int *exp);
double ldexp(double x, int n);
long double ldexpl(long double x, int n);
double floor(double x);
double ceil(double x);
double sqrt(double x);
double sin(double x);
double cos(double x);
double tan(double x);
double asin(double x);
double acos(double x);
double atan(double x);
double atan2(double y, double x);
double pow(double base, double exp);
@@ -26,6 +31,9 @@ double log2(double x);
double log10(double x);
double exp(double x);
double fmod(double x, double y);
double sinh(double x);
double cosh(double x);
double tanh(double x);
double round(double x);
float floorf(float x);
+19
View File
@@ -0,0 +1,19 @@
#ifndef _LIBC_SETJMP_H
#define _LIBC_SETJMP_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long jmp_buf[8];
int setjmp(jmp_buf env);
void longjmp(jmp_buf env, int val) __attribute__((noreturn));
#ifdef __cplusplus
}
#endif
#endif /* _LIBC_SETJMP_H */
+26
View File
@@ -0,0 +1,26 @@
#ifndef _LIBC_SIGNAL_H
#define _LIBC_SIGNAL_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef int sig_atomic_t;
typedef void (*sighandler_t)(int);
#define SIGINT 2
#define SIG_DFL ((sighandler_t)0)
#define SIG_IGN ((sighandler_t)1)
#define SIG_ERR ((sighandler_t)-1)
sighandler_t signal(int sig, sighandler_t handler);
int raise(int sig);
#ifdef __cplusplus
}
#endif
#endif /* _LIBC_SIGNAL_H */
+8
View File
@@ -16,6 +16,11 @@ extern "C" {
#define SEEK_END 2
#define BUFSIZ 1024
#define FILENAME_MAX 256
#define L_tmpnam 64
#define TMP_MAX 10000
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
typedef struct _FILE {
int handle;
@@ -50,6 +55,8 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
int fflush(FILE *stream);
FILE *freopen(const char *path, const char *mode, FILE *stream);
int setvbuf(FILE *stream, char *buf, int mode, size_t size);
int rename(const char *oldpath, const char *newpath);
int remove(const char *path);
@@ -62,6 +69,7 @@ void clearerr(FILE *stream);
int fgetc(FILE *stream);
int getc(FILE *stream);
int fputc(int c, FILE *stream);
int ungetc(int c, FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int fputs(const char *s, FILE *stream);
+6
View File
@@ -44,12 +44,18 @@ void abort(void);
int atexit(void (*func)(void));
char *getenv(const char *name);
int setenv(const char *name, const char *value, int overwrite);
int unsetenv(const char *name);
int putenv(char *string);
void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
long strtol(const char *nptr, char **endptr, int base);
unsigned long strtoul(const char *nptr, char **endptr, int base);
double strtod(const char *nptr, char **endptr);
float strtof(const char *nptr, char **endptr);
long double strtold(const char *nptr, char **endptr);
int rand(void);
void srand(unsigned int seed);
+5
View File
@@ -16,6 +16,8 @@ int memcmp(const void *s1, const void *s2, size_t n);
void *memchr(const void *s, int c, size_t n);
size_t strlen(const char *s);
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *strcpy(char *dest, const char *src);
@@ -25,9 +27,12 @@ char *strncat(char *dest, const char *src, size_t n);
char *strdup(const char *s);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strpbrk(const char *s, const char *accept);
int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, size_t n);
int strcoll(const char *s1, const char *s2);
char *strstr(const char *haystack, const char *needle);
const char *strerror(int errnum);
#ifdef __cplusplus
}
+10 -1
View File
@@ -3,14 +3,23 @@
#pragma once
#include <stddef.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define S_IFMT 0170000
#define S_IFDIR 0040000
#define S_IFREG 0100000
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
struct stat {
mode_t st_mode;
unsigned long st_size;
time_t st_mtime;
};
int mkdir(const char *path, unsigned int mode);
+2
View File
@@ -17,6 +17,8 @@ struct timezone {
int tz_dsttime;
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
#ifdef __cplusplus
}
#endif
+41
View File
@@ -0,0 +1,41 @@
#ifndef _LIBC_TIME_H
#define _LIBC_TIME_H
#pragma once
#include <stddef.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef long clock_t;
#define CLOCKS_PER_SEC 1000L
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
clock_t clock(void);
time_t time(time_t *tloc);
double difftime(time_t time1, time_t time0);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
time_t mktime(struct tm *tm);
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
#ifdef __cplusplus
}
#endif
#endif /* _LIBC_TIME_H */
+7
View File
@@ -9,12 +9,19 @@
extern "C" {
#endif
#define F_OK 0
#define X_OK 1
#define W_OK 2
#define R_OK 4
int read(int fd, void *buf, size_t count);
int write(int fd, const void *buf, size_t count);
int close(int fd);
long lseek(int fd, long offset, int whence);
int chdir(const char *path);
char *getcwd(char *buf, size_t size);
int access(const char *path, int mode);
int isatty(int fd);
unsigned int sleep(unsigned int seconds);