diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-11-29 14:42:36 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-11-29 14:42:36 +0800 |
| commit | 8953ecec306536cd0b18c9de316461ad4c35166f (patch) | |
| tree | b58d7e30d428048ea727bbb0568eb2c49267ee98 | |
| parent | 2d1a087a70272dc32183bbd3d5b0c036bc26ffdb (diff) | |
| download | yuescript-8953ecec306536cd0b18c9de316461ad4c35166f.tar.gz yuescript-8953ecec306536cd0b18c9de316461ad4c35166f.tar.bz2 yuescript-8953ecec306536cd0b18c9de316461ad4c35166f.zip | |
fix issue #70.
Diffstat (limited to '')
| -rw-r--r-- | src/yue.cpp | 12 | ||||
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 2 | ||||
| -rw-r--r-- | src/yuescript/yuescript.cpp | 4 |
3 files changed, 17 insertions, 1 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index 1704b57..133a081 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -37,7 +37,12 @@ int luaopen_yue(lua_State* L); | |||
| 37 | static void openlibs(void* state) { | 37 | static void openlibs(void* state) { |
| 38 | lua_State* L = static_cast<lua_State*>(state); | 38 | lua_State* L = static_cast<lua_State*>(state); |
| 39 | luaL_openlibs(L); | 39 | luaL_openlibs(L); |
| 40 | #if LUA_VERSION_NUM > 501 | ||
| 40 | luaL_requiref(L, "yue", luaopen_yue, 1); | 41 | luaL_requiref(L, "yue", luaopen_yue, 1); |
| 42 | #else | ||
| 43 | lua_pushcfunction(L, luaopen_yue); | ||
| 44 | lua_call(L, 0, 0); | ||
| 45 | #endif | ||
| 41 | lua_pop(L, 1); | 46 | lua_pop(L, 1); |
| 42 | } | 47 | } |
| 43 | 48 | ||
| @@ -238,7 +243,14 @@ int main(int narg, const char** args) { | |||
| 238 | if (success) { | 243 | if (success) { |
| 239 | if (retCount > 1) { | 244 | if (retCount > 1) { |
| 240 | for (int i = 1; i < retCount; ++i) { | 245 | for (int i = 1; i < retCount; ++i) { |
| 246 | #if LUA_VERSION_NUM > 501 | ||
| 241 | std::cout << Val << luaL_tolstring(L, -retCount + i, nullptr) << Stop; | 247 | std::cout << Val << luaL_tolstring(L, -retCount + i, nullptr) << Stop; |
| 248 | #else // LUA_VERSION_NUM | ||
| 249 | lua_getglobal(L, "tostring"); | ||
| 250 | lua_pushvalue(L, -retCount + i - 1); | ||
| 251 | lua_call(L, 1, 1); | ||
| 252 | std::cout << Val << lua_tostring(L, -1) << Stop; | ||
| 253 | #endif // LUA_VERSION_NUM | ||
| 242 | lua_pop(L, 1); | 254 | lua_pop(L, 1); |
| 243 | } | 255 | } |
| 244 | } | 256 | } |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index d4996a7..e93324e 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -60,7 +60,7 @@ using namespace parserlib; | |||
| 60 | 60 | ||
| 61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
| 62 | 62 | ||
| 63 | const std::string_view version = "0.9.2"sv; | 63 | const std::string_view version = "0.9.3"sv; |
| 64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
| 65 | 65 | ||
| 66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp index b83a454..87aa917 100644 --- a/src/yuescript/yuescript.cpp +++ b/src/yuescript/yuescript.cpp | |||
| @@ -133,7 +133,11 @@ static const luaL_Reg yuelib[] = { | |||
| 133 | }; | 133 | }; |
| 134 | 134 | ||
| 135 | int luaopen_yue(lua_State* L) { | 135 | int luaopen_yue(lua_State* L) { |
| 136 | #if LUA_VERSION_NUM > 501 | ||
| 136 | luaL_newlib(L, yuelib); // yue | 137 | luaL_newlib(L, yuelib); // yue |
| 138 | #else | ||
| 139 | luaL_register(L, "yue", yuelib); // yue | ||
| 140 | #endif | ||
| 137 | lua_pushlstring(L, &yue::version.front(), yue::version.size()); // yue version | 141 | lua_pushlstring(L, &yue::version.front(), yue::version.size()); // yue version |
| 138 | lua_setfield(L, -2, "version"); // yue["version"] = version, yue | 142 | lua_setfield(L, -2, "version"); // yue["version"] = version, yue |
| 139 | lua_createtable(L, 0, 0); // yue options | 143 | lua_createtable(L, 0, 0); // yue options |
