aboutsummaryrefslogtreecommitdiff
path: root/c-api/compat-5.3.c
diff options
context:
space:
mode:
Diffstat (limited to 'c-api/compat-5.3.c')
-rw-r--r--c-api/compat-5.3.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c
index 96b38cc..883efb8 100644
--- a/c-api/compat-5.3.c
+++ b/c-api/compat-5.3.c
@@ -236,40 +236,6 @@ COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname) {
236} 236}
237 237
238 238
239COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
240 if (!luaL_callmeta(L, idx, "__tostring")) {
241 int t = lua_type(L, idx), tt = 0;
242 char const* name = NULL;
243 switch (t) {
244 case LUA_TNIL:
245 lua_pushliteral(L, "nil");
246 break;
247 case LUA_TSTRING:
248 case LUA_TNUMBER:
249 lua_pushvalue(L, idx);
250 break;
251 case LUA_TBOOLEAN:
252 if (lua_toboolean(L, idx))
253 lua_pushliteral(L, "true");
254 else
255 lua_pushliteral(L, "false");
256 break;
257 default:
258 tt = luaL_getmetafield(L, idx, "__name");
259 name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t);
260 lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx));
261 if (tt != LUA_TNIL)
262 lua_replace(L, -2);
263 break;
264 }
265 } else {
266 if (!lua_isstring(L, -1))
267 luaL_error(L, "'__tostring' must return a string");
268 }
269 return lua_tolstring(L, -1, len);
270}
271
272
273static int compat53_countlevels (lua_State *L) { 239static int compat53_countlevels (lua_State *L) {
274 lua_Debug ar; 240 lua_Debug ar;
275 int li = 1, le = 1; 241 int li = 1, le = 1;
@@ -564,6 +530,40 @@ COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s) {
564} 530}
565 531
566 532
533COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
534 if (!luaL_callmeta(L, idx, "__tostring")) {
535 int t = lua_type(L, idx), tt = 0;
536 char const* name = NULL;
537 switch (t) {
538 case LUA_TNIL:
539 lua_pushliteral(L, "nil");
540 break;
541 case LUA_TSTRING:
542 case LUA_TNUMBER:
543 lua_pushvalue(L, idx);
544 break;
545 case LUA_TBOOLEAN:
546 if (lua_toboolean(L, idx))
547 lua_pushliteral(L, "true");
548 else
549 lua_pushliteral(L, "false");
550 break;
551 default:
552 tt = luaL_getmetafield(L, idx, "__name");
553 name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t);
554 lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx));
555 if (tt != LUA_TNIL)
556 lua_replace(L, -2);
557 break;
558 }
559 } else {
560 if (!lua_isstring(L, -1))
561 luaL_error(L, "'__tostring' must return a string");
562 }
563 return lua_tolstring(L, -1, len);
564}
565
566
567COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, 567COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
568 lua_CFunction openf, int glb) { 568 lua_CFunction openf, int glb) {
569 luaL_checkstack(L, 3, "not enough stack slots available"); 569 luaL_checkstack(L, 3, "not enough stack slots available");