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