This commit is contained in:
lenheart
2024-05-22 19:26:48 +08:00
parent ce8b5fd1b3
commit 1f2ddbabe5
240 changed files with 57785 additions and 510 deletions

View File

@@ -1,32 +1,54 @@
#include "l_squirrel.h"
#include "l_squirrel_register.hpp"
#include "spdlog/spdlog.h"
// 虚拟机对象
HSQUIRRELVM v;
// Lock
std::recursive_mutex SqMtx;
// static void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
// {
// fflush(stdout);
// va_list vl;
// va_start(vl, s);
// scvprintf(stdout, s, vl);
// va_end(vl);
// printf("\n");
// fflush(stdout);
// }
static void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
{
fflush(stdout);
va_list vl;
va_start(vl, s);
scvprintf(stdout, s, vl);
char buf[1024];
vsnprintf(buf, sizeof(buf), s, vl);
va_end(vl);
printf("\n");
fflush(stdout);
spdlog::info(buf);
}
// static void errorfunc(HSQUIRRELVM v, const SQChar *s, ...)
// {
// fflush(stderr);
// va_list vl;
// va_start(vl, s);
// scvprintf(stderr, s, vl);
// va_end(vl);
// printf("\n");
// fflush(stderr);
// }
static void errorfunc(HSQUIRRELVM v, const SQChar *s, ...)
{
fflush(stderr);
va_list vl;
va_start(vl, s);
scvprintf(stderr, s, vl);
char buf[1024];
vsnprintf(buf, sizeof(buf), s, vl);
va_end(vl);
printf("\n");
fflush(stderr);
spdlog::error(buf);
}
// 加密函数
static std::string encryptDecrypt(const std::string &input, const std::string &key)
{
@@ -141,6 +163,8 @@ void InitSquirrel()
sqstd_register_stringlib(v);
sqstd_seterrorhandlers(v);
// 设置日志格式
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
sq_setprintfunc(v, printfunc, errorfunc); // sets the print function
// 输出版本信息