diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-11-04 17:00:46 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-11-04 17:00:46 +0800 |
| commit | ccd9c7f216c341b50e0a0313ac2eef6a89cee5a4 (patch) | |
| tree | 153ce8766144c7f4288772a1fe668590f60e42a5 /src/yue.cpp | |
| parent | 03d4fad6ef79ce1788391648e535039a5f29aec3 (diff) | |
| download | yuescript-ccd9c7f216c341b50e0a0313ac2eef6a89cee5a4.tar.gz yuescript-ccd9c7f216c341b50e0a0313ac2eef6a89cee5a4.tar.bz2 yuescript-ccd9c7f216c341b50e0a0313ac2eef6a89cee5a4.zip | |
Included a minimal json lib in yue compiler tool.
Diffstat (limited to 'src/yue.cpp')
| -rw-r--r-- | src/yue.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index 2c3a469..aebc31d 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -72,18 +72,26 @@ extern "C" { | |||
| 72 | #include "lua.h" | 72 | #include "lua.h" |
| 73 | #include "lualib.h" | 73 | #include "lualib.h" |
| 74 | int luaopen_yue(lua_State* L); | 74 | int luaopen_yue(lua_State* L); |
| 75 | int luaopen_colibc_json(lua_State* L); | ||
| 75 | } // extern "C" | 76 | } // extern "C" |
| 76 | 77 | ||
| 77 | static void openlibs(void* state) { | 78 | static void openlibs(void* state) { |
| 78 | lua_State* L = static_cast<lua_State*>(state); | 79 | lua_State* L = static_cast<lua_State*>(state); |
| 79 | luaL_openlibs(L); | 80 | luaL_openlibs(L); |
| 81 | int top = lua_gettop(L); | ||
| 80 | #if LUA_VERSION_NUM > 501 | 82 | #if LUA_VERSION_NUM > 501 |
| 81 | luaL_requiref(L, "yue", luaopen_yue, 0); | 83 | luaL_requiref(L, "yue", luaopen_yue, 0); |
| 84 | luaL_requiref(L, "json", luaopen_colibc_json, 0); | ||
| 82 | #else | 85 | #else |
| 83 | lua_pushcfunction(L, luaopen_yue); | 86 | lua_pushcfunction(L, luaopen_yue); |
| 84 | lua_call(L, 0, 0); | 87 | lua_call(L, 0, 0); |
| 88 | lua_getglobal(L, "package"); // package | ||
| 89 | lua_getfield(L, -1, "loaded"); // package loaded | ||
| 90 | lua_pushcfunction(L, luaopen_colibc_json); | ||
| 91 | lua_call(L, 0, 1); // package loaded json | ||
| 92 | lua_setfield(L, -2, "json"); // loaded["json"] = json, package loaded | ||
| 85 | #endif | 93 | #endif |
| 86 | lua_pop(L, 1); | 94 | lua_settop(L, top); |
| 87 | } | 95 | } |
| 88 | 96 | ||
| 89 | void pushYue(lua_State* L, std::string_view name) { | 97 | void pushYue(lua_State* L, std::string_view name) { |
