尝试重写 dofile 文件流成功

This commit is contained in:
2022-02-15 20:31:51 +08:00
parent 6237ecd17f
commit b2d797c480
3 changed files with 35 additions and 14 deletions

View File

@@ -240,7 +240,9 @@ int GetEquAddr(int addr)
//加载
static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
{
void* file = SQfopen(filename, L"rb");
SQFILE* file = SQfopen(filename, L"rb+");
//FILE* file;
//file = fopen(filename, "rb");
int ret;
unsigned short us;
unsigned char uc;
@@ -283,18 +285,26 @@ static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
default: SQfseek(file, 0, 2); break; // ascii
}
const char *add = "newstr";
int prevpos = SQftell(file);
char* nstr = (char*)"IIIAAAB <- 6648";
//SQwrite(&add, 1, sizeof(add), file);
SQwrite(nstr, sizeof(nstr), strlen(nstr), file);
SQfseek(file, 0, 1);
int length = SQftell(file);
SQfseek(file, prevpos, 2);
char temp[256];
SQwrite(&add, 1, sizeof(add), file);
SQfread(&temp, length + 10, sizeof(temp), file);
std::cout << temp << std::endl;
SQfseek(file, 0, 2);
std::cout << "lenth:" << length << std::endl;
//char temp[256];
char* temp = new char[length];
//SQwrite(&add, 1, sizeof(add), file);
SQfread(temp, sizeof(temp), length, file);
temp[length] = '\0';
printf(temp);
printf("\n");
//std::cout << temp << std::endl;
//char* temp = new char[16 * 4];
SQfseek(file, 0, 2);
if (SQ_Compile(v, func, file, filename, printerror) >= 0)
{
SQ__Fclose(file);
@@ -361,7 +371,6 @@ void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v)
static int sq_Test(uint32_t v)
{
//sq_pushinteger(v, n1);
SQdofile(v, L"1.cpp", false, false);
return 0;
}
//读人物 或 装备属性
@@ -618,6 +627,14 @@ static int LDofile(uint32_t v)
{
SQGetString(v, 2, &n1);
SQPopTop(v);
/*
size_t len = wcslen(n1) + 1;
size_t converted = 0;
char* CStr;
CStr = (char*)malloc(len * sizeof(char));
wcstombs_s(&converted, CStr, len, n1, _TRUNCATE);
*/
SQdofile(v, n1, false, false);
SQPushBool(v, true);
}