Files
lity3d/Engine/Scripting/lua_engine.c
T
shuiyu1123 2d56cb3bc9 MiMoEngine ASM: x86-64 MASM汇编+C混合架构游戏引擎
核心热路径(数学/内存/字符串/性能分析)用MASM汇编(SSE/AVX2)
外围系统(窗口/渲染/ECS/音频/UI/脚本)用C语言
含自研编辑器、VisualScript积木编程、中文渲染(glyph_atlas)
2026-07-10 19:20:40 +08:00

61 lines
1.6 KiB
C

#include "lua_engine.h"
#include <stdlib.h>
#include <stdio.h>
// Lua头文件 (需要单独下载或集成)
// #include <lua.h>
// #include <lualib.h>
// #include <lauxlib.h>
// 由于Lua需要单独集成,这里提供占位实现
// 实际使用时取消注释并链接Lua库
typedef struct lua_State lua_State;
static lua_State* luaL_newstate(void) { return NULL; }
static void luaL_openlibs(lua_State* L) { (void)L; }
static int luaL_dofile(lua_State* L, const char* fn) { (void)L; (void)fn; return -1; }
static int luaL_dostring(lua_State* L, const char* s) { (void)L; (void)s; return -1; }
static void lua_close(lua_State* L) { (void)L; }
LuaEngine* lua_engine_create(void) {
return (LuaEngine*)calloc(1, sizeof(LuaEngine));
}
void lua_engine_destroy(LuaEngine* engine) {
if (!engine) return;
if (engine->L) lua_close(engine->L);
free(engine);
}
int lua_engine_init(LuaEngine* engine) {
engine->L = luaL_newstate();
if (!engine->L) return -1;
luaL_openlibs(engine->L);
engine->initialized = 1;
return 0;
}
int lua_engine_do_file(LuaEngine* engine, const char* path) {
if (!engine->L) return -1;
return luaL_dofile(engine->L, path);
}
int lua_engine_do_string(LuaEngine* engine, const char* code) {
if (!engine->L) return -1;
return luaL_dostring(engine->L, code);
}
void lua_engine_register_function(LuaEngine* engine, const char* name, void* func) {
(void)engine;
(void)name;
(void)func;
// lua_pushcfunction(engine->L, func);
// lua_setglobal(engine->L, name);
}
lua_State* lua_engine_get_state(LuaEngine* engine) {
return engine->L;
}