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 /src/yue.cpp | |
parent | 2d1a087a70272dc32183bbd3d5b0c036bc26ffdb (diff) | |
download | yuescript-8953ecec306536cd0b18c9de316461ad4c35166f.tar.gz yuescript-8953ecec306536cd0b18c9de316461ad4c35166f.tar.bz2 yuescript-8953ecec306536cd0b18c9de316461ad4c35166f.zip |
fix issue #70.
Diffstat (limited to 'src/yue.cpp')
-rw-r--r-- | src/yue.cpp | 12 |
1 files changed, 12 insertions, 0 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 | } |