[NEW] feof(), freadw(), fwritew()
This commit is contained in:
19
lua.cpp
19
lua.cpp
@@ -525,6 +525,11 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_feof(lua_State *L) {
|
||||
lua_pushboolean(L,feof());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_fwritei(lua_State *L) {
|
||||
int value = luaL_checkinteger(L, 1);
|
||||
fwritei(value);
|
||||
@@ -543,6 +548,12 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_fwritew(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
fwritew(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_fwriteb(lua_State *L) {
|
||||
bool value = lua_toboolean(L, 1);
|
||||
fwriteb(value);
|
||||
@@ -569,6 +580,11 @@ extern "C" {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_freadw(lua_State *L) {
|
||||
lua_pushstring(L,freadw());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_freadb(lua_State *L) {
|
||||
lua_pushboolean(L,freadb());
|
||||
return 1;
|
||||
@@ -656,14 +672,17 @@ void push_lua_funcs() {
|
||||
|
||||
lua_pushcfunction(L,cpp_fopen); lua_setglobal(L, "fopen");
|
||||
lua_pushcfunction(L,cpp_fclose); lua_setglobal(L, "fclose");
|
||||
lua_pushcfunction(L,cpp_feof); lua_setglobal(L, "feof");
|
||||
lua_pushcfunction(L,cpp_fwritei); lua_setglobal(L, "fwritei");
|
||||
lua_pushcfunction(L,cpp_fwrited); lua_setglobal(L, "fwrited");
|
||||
lua_pushcfunction(L,cpp_fwrites); lua_setglobal(L, "fwrites");
|
||||
lua_pushcfunction(L,cpp_fwritew); lua_setglobal(L, "fwritew");
|
||||
lua_pushcfunction(L,cpp_fwriteb); lua_setglobal(L, "fwriteb");
|
||||
lua_pushcfunction(L,cpp_fwriteln); lua_setglobal(L, "fwriteln");
|
||||
lua_pushcfunction(L,cpp_freadi); lua_setglobal(L, "freadi");
|
||||
lua_pushcfunction(L,cpp_freadd); lua_setglobal(L, "freadd");
|
||||
lua_pushcfunction(L,cpp_freads); lua_setglobal(L, "freads");
|
||||
lua_pushcfunction(L,cpp_freadw); lua_setglobal(L, "freadw");
|
||||
lua_pushcfunction(L,cpp_freadb); lua_setglobal(L, "freadb");
|
||||
|
||||
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||
|
||||
17
mini.cpp
17
mini.cpp
@@ -928,24 +928,30 @@ void fclose() {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
bool feof() {
|
||||
return feof(file);
|
||||
}
|
||||
|
||||
void fwritei(int value) {
|
||||
sprintf(fstr, "%i ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwrited(float value) {
|
||||
char str[255];
|
||||
sprintf(fstr, "%f ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
void fwrites(const char *value) {
|
||||
char str[255];
|
||||
sprintf(fstr, "\"%s\" ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwritew(const char *value) {
|
||||
sprintf(fstr, "%s ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteb(bool value) {
|
||||
char str[255];
|
||||
sprintf(fstr, value?"true ":"false ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
@@ -971,6 +977,11 @@ const char *freads() {
|
||||
return fstr;
|
||||
}
|
||||
|
||||
const char *freadw() {
|
||||
fscanf(file, "%s", &fstr);
|
||||
return fstr;
|
||||
}
|
||||
|
||||
bool freadb() {
|
||||
fscanf(file, "%s", &fstr);
|
||||
return strcmp(fstr, "true")==0?true:false;
|
||||
|
||||
3
mini.h
3
mini.h
@@ -232,14 +232,17 @@ uint8_t ascii(const char *str, uint8_t index);
|
||||
|
||||
void fopen(const char *filename, uint8_t mode=0);
|
||||
void fclose();
|
||||
bool feof();
|
||||
|
||||
void fwritei(int value);
|
||||
void fwrited(float value);
|
||||
void fwrites(const char *value);
|
||||
void fwritew(const char *value);
|
||||
void fwriteb(bool value);
|
||||
void fwriteln();
|
||||
|
||||
int freadi();
|
||||
float freadd();
|
||||
const char *freads();
|
||||
const char *freadw();
|
||||
bool freadb();
|
||||
|
||||
Reference in New Issue
Block a user