lbaselib.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. ** $Id: lbaselib.c,v 1.5 2000/09/14 14:09:31 roberto Exp roberto $
  3. ** Basic library
  4. ** See Copyright Notice in lua.h
  5. */
  6. #include <ctype.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "lua.h"
  11. #include "lauxlib.h"
  12. #include "luadebug.h"
  13. #include "lualib.h"
  14. /*
  15. ** If your system does not support `stderr', redefine this function, or
  16. ** redefine _ERRORMESSAGE so that it won't need _ALERT.
  17. */
  18. static int luaB__ALERT (lua_State *L) {
  19. fputs(luaL_check_string(L, 1), stderr);
  20. return 0;
  21. }
  22. /*
  23. ** Basic implementation of _ERRORMESSAGE.
  24. ** The library `liolib' redefines _ERRORMESSAGE for better error information.
  25. */
  26. static int luaB__ERRORMESSAGE (lua_State *L) {
  27. luaL_checktype(L, 1, "string");
  28. lua_getglobal(L, LUA_ALERT);
  29. if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
  30. lua_Debug ar;
  31. lua_pushstring(L, "error: ");
  32. lua_pushvalue(L, 1);
  33. if (lua_getstack(L, 1, &ar)) {
  34. lua_getinfo(L, "Sl", &ar);
  35. if (ar.source && ar.currentline > 0) {
  36. char buff[100];
  37. sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline);
  38. lua_pushstring(L, buff);
  39. lua_concat(L, 2);
  40. }
  41. }
  42. lua_pushstring(L, "\n");
  43. lua_concat(L, 3);
  44. lua_rawcall(L, 1, 0);
  45. }
  46. return 0;
  47. }
  48. /*
  49. ** If your system does not support `stdout', you can just remove this function.
  50. ** If you need, you can define your own `print' function, following this
  51. ** model but changing `fputs' to put the strings at a proper place
  52. ** (a console window or a log file, for instance).
  53. */
  54. static int luaB_print (lua_State *L) {
  55. int n = lua_gettop(L); /* number of arguments */
  56. int i;
  57. lua_getglobal(L, "tostring");
  58. for (i=1; i<=n; i++) {
  59. const char *s;
  60. lua_pushvalue(L, -1); /* function to be called */
  61. lua_pushvalue(L, i); /* value to print */
  62. lua_rawcall(L, 1, 1);
  63. s = lua_tostring(L, -1); /* get result */
  64. if (s == NULL)
  65. lua_error(L, "`tostring' must return a string to `print'");
  66. if (i>1) fputs("\t", stdout);
  67. fputs(s, stdout);
  68. lua_pop(L, 1); /* pop result */
  69. }
  70. fputs("\n", stdout);
  71. return 0;
  72. }
  73. static int luaB_tonumber (lua_State *L) {
  74. int base = luaL_opt_int(L, 2, 10);
  75. if (base == 10) { /* standard conversion */
  76. luaL_checktype(L, 1, "any");
  77. if (lua_isnumber(L, 1)) {
  78. lua_pushnumber(L, lua_tonumber(L, 1));
  79. return 1;
  80. }
  81. }
  82. else {
  83. const char *s1 = luaL_check_string(L, 1);
  84. char *s2;
  85. unsigned long n;
  86. luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range");
  87. n = strtoul(s1, &s2, base);
  88. if (s1 != s2) { /* at least one valid digit? */
  89. while (isspace((unsigned char)*s2)) s2++; /* skip trailing spaces */
  90. if (*s2 == '\0') { /* no invalid trailing characters? */
  91. lua_pushnumber(L, n);
  92. return 1;
  93. }
  94. }
  95. }
  96. lua_pushnil(L); /* else not a number */
  97. return 1;
  98. }
  99. static int luaB_error (lua_State *L) {
  100. lua_error(L, luaL_opt_string(L, 1, NULL));
  101. return 0; /* to avoid warnings */
  102. }
  103. static int luaB_setglobal (lua_State *L) {
  104. luaL_checktype(L, 2, "any");
  105. lua_setglobal(L, luaL_check_string(L, 1));
  106. return 0;
  107. }
  108. static int luaB_getglobal (lua_State *L) {
  109. lua_getglobal(L, luaL_check_string(L, 1));
  110. return 1;
  111. }
  112. static int luaB_tag (lua_State *L) {
  113. luaL_checktype(L, 1, "any");
  114. lua_pushnumber(L, lua_tag(L, 1));
  115. return 1;
  116. }
  117. static int luaB_settag (lua_State *L) {
  118. luaL_checktype(L, 1, "table");
  119. lua_pushvalue(L, 1); /* push table */
  120. lua_settag(L, luaL_check_int(L, 2));
  121. lua_pop(L, 1); /* remove second argument */
  122. return 1; /* return first argument */
  123. }
  124. static int luaB_newtag (lua_State *L) {
  125. lua_pushnumber(L, lua_newtag(L));
  126. return 1;
  127. }
  128. static int luaB_copytagmethods (lua_State *L) {
  129. lua_pushnumber(L, lua_copytagmethods(L, luaL_check_int(L, 1),
  130. luaL_check_int(L, 2)));
  131. return 1;
  132. }
  133. static int luaB_globals (lua_State *L) {
  134. lua_getglobals(L); /* value to be returned */
  135. if (!lua_isnull(L, 1)) {
  136. luaL_checktype(L, 1, "table");
  137. lua_pushvalue(L, 1); /* new table of globals */
  138. lua_setglobals(L);
  139. }
  140. return 1;
  141. }
  142. static int luaB_rawget (lua_State *L) {
  143. luaL_checktype(L, 1, "table");
  144. luaL_checktype(L, 2, "any");
  145. lua_rawget(L, -2);
  146. return 1;
  147. }
  148. static int luaB_rawset (lua_State *L) {
  149. luaL_checktype(L, 1, "table");
  150. luaL_checktype(L, 2, "any");
  151. luaL_checktype(L, 3, "any");
  152. lua_rawset(L, -3);
  153. return 1;
  154. }
  155. static int luaB_settagmethod (lua_State *L) {
  156. int tag = (int)luaL_check_int(L, 1);
  157. const char *event = luaL_check_string(L, 2);
  158. luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3,
  159. "function or nil expected");
  160. lua_pushnil(L); /* to get its tag */
  161. if (strcmp(event, "gc") == 0 && tag != lua_tag(L, -1))
  162. lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua");
  163. lua_pop(L, 1); /* remove the nil */
  164. lua_settagmethod(L, tag, event);
  165. return 1;
  166. }
  167. static int luaB_gettagmethod (lua_State *L) {
  168. lua_gettagmethod(L, luaL_check_int(L, 1), luaL_check_string(L, 2));
  169. return 1;
  170. }
  171. static int luaB_collectgarbage (lua_State *L) {
  172. lua_pushnumber(L, lua_collectgarbage(L, luaL_opt_int(L, 1, 0)));
  173. return 1;
  174. }
  175. static int luaB_type (lua_State *L) {
  176. luaL_checktype(L, 1, "any");
  177. lua_pushstring(L, lua_type(L, 1));
  178. return 1;
  179. }
  180. static int luaB_next (lua_State *L) {
  181. luaL_checktype(L, 1, "table");
  182. lua_settop(L, 2); /* create a 2nd argument if there isn't one */
  183. if (lua_next(L, 1))
  184. return 2;
  185. else {
  186. lua_pushnil(L);
  187. return 1;
  188. }
  189. }
  190. static int passresults (lua_State *L, int status, int oldtop) {
  191. static const char *const errornames[] =
  192. {"ok", "run-time error", "file error", "syntax error", "memory error"};
  193. if (status == 0) {
  194. int nresults = lua_gettop(L) - oldtop;
  195. if (nresults > 0)
  196. return nresults; /* results are already on the stack */
  197. else {
  198. lua_pushuserdata(L, NULL); /* at least one result to signal no errors */
  199. return 1;
  200. }
  201. }
  202. else { /* error */
  203. lua_pushnil(L);
  204. lua_pushstring(L, errornames[status]); /* error code */
  205. return 2;
  206. }
  207. }
  208. static int luaB_dostring (lua_State *L) {
  209. int oldtop = lua_gettop(L);
  210. size_t l;
  211. const char *s = luaL_check_lstr(L, 1, &l);
  212. if (*s == '\27') /* binary files start with ESC... */
  213. lua_error(L, "`dostring' cannot run pre-compiled code");
  214. return passresults(L, lua_dobuffer(L, s, l, luaL_opt_string(L, 2, s)), oldtop);
  215. }
  216. static int luaB_dofile (lua_State *L) {
  217. int oldtop = lua_gettop(L);
  218. const char *fname = luaL_opt_string(L, 1, NULL);
  219. return passresults(L, lua_dofile(L, fname), oldtop);
  220. }
  221. static int luaB_call (lua_State *L) {
  222. int oldtop;
  223. const char *options = luaL_opt_string(L, 3, "");
  224. int err = 0; /* index of old error method */
  225. int i, status;
  226. int n;
  227. luaL_checktype(L, 2, "table");
  228. n = lua_getn(L, 2);
  229. if (!lua_isnull(L, 4)) { /* set new error method */
  230. lua_getglobal(L, LUA_ERRORMESSAGE);
  231. err = lua_gettop(L); /* get index */
  232. lua_pushvalue(L, 4);
  233. lua_setglobal(L, LUA_ERRORMESSAGE);
  234. }
  235. oldtop = lua_gettop(L); /* top before function-call preparation */
  236. /* push function */
  237. lua_pushvalue(L, 1);
  238. luaL_checkstack(L, n, "too many arguments");
  239. for (i=0; i<n; i++) /* push arg[1...n] */
  240. lua_rawgeti(L, 2, i+1);
  241. status = lua_call(L, n, LUA_MULTRET);
  242. if (err != 0) { /* restore old error method */
  243. lua_pushvalue(L, err);
  244. lua_setglobal(L, LUA_ERRORMESSAGE);
  245. }
  246. if (status != 0) { /* error in call? */
  247. if (strchr(options, 'x'))
  248. lua_pushnil(L); /* return nil to signal the error */
  249. else
  250. lua_error(L, NULL); /* propagate error without additional messages */
  251. return 1;
  252. }
  253. if (strchr(options, 'p')) /* pack results? */
  254. lua_error(L, "deprecated option `p' in `call'");
  255. return lua_gettop(L) - oldtop; /* results are already on the stack */
  256. }
  257. static int luaB_tostring (lua_State *L) {
  258. char buff[64];
  259. switch (lua_type(L, 1)[2]) {
  260. case 'm': /* nuMber */
  261. lua_pushstring(L, lua_tostring(L, 1));
  262. return 1;
  263. case 'r': /* stRing */
  264. lua_pushvalue(L, 1);
  265. return 1;
  266. case 'b': /* taBle */
  267. sprintf(buff, "table: %p", lua_topointer(L, 1));
  268. break;
  269. case 'n': /* fuNction */
  270. sprintf(buff, "function: %p", lua_topointer(L, 1));
  271. break;
  272. case 'e': /* usErdata */
  273. sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
  274. break;
  275. case 'l': /* niL */
  276. lua_pushstring(L, "nil");
  277. return 1;
  278. default:
  279. luaL_argerror(L, 1, "value expected");
  280. }
  281. lua_pushstring(L, buff);
  282. return 1;
  283. }
  284. static int luaB_foreachi (lua_State *L) {
  285. int n, i;
  286. luaL_checktype(L, 1, "table");
  287. luaL_checktype(L, 2, "function");
  288. n = lua_getn(L, 1);
  289. for (i=1; i<=n; i++) {
  290. lua_pushvalue(L, 2); /* function */
  291. lua_pushnumber(L, i); /* 1st argument */
  292. lua_rawgeti(L, 1, i); /* 2nd argument */
  293. lua_rawcall(L, 2, 1);
  294. if (!lua_isnil(L, -1))
  295. return 1;
  296. lua_pop(L, 1); /* remove nil result */
  297. }
  298. return 0;
  299. }
  300. static int luaB_foreach (lua_State *L) {
  301. luaL_checktype(L, 1, "table");
  302. luaL_checktype(L, 2, "function");
  303. lua_pushnil(L); /* first index */
  304. for (;;) {
  305. if (lua_next(L, 1) == 0)
  306. return 0;
  307. lua_pushvalue(L, 2); /* function */
  308. lua_pushvalue(L, -3); /* key */
  309. lua_pushvalue(L, -3); /* value */
  310. lua_rawcall(L, 2, 1);
  311. if (!lua_isnil(L, -1))
  312. return 1;
  313. lua_pop(L, 2); /* remove value and result */
  314. }
  315. }
  316. static int luaB_assert (lua_State *L) {
  317. luaL_checktype(L, 1, "any");
  318. if (lua_isnil(L, 1))
  319. luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
  320. return 0;
  321. }
  322. static int luaB_getn (lua_State *L) {
  323. luaL_checktype(L, 1, "table");
  324. lua_pushnumber(L, lua_getn(L, 1));
  325. return 1;
  326. }
  327. static int luaB_tinsert (lua_State *L) {
  328. int v = lua_gettop(L); /* last argument: to be inserted */
  329. int n, pos;
  330. luaL_checktype(L, 1, "table");
  331. n = lua_getn(L, 1);
  332. if (v == 2) /* called with only 2 arguments */
  333. pos = n+1;
  334. else
  335. pos = luaL_check_int(L, 2); /* 2nd argument is the position */
  336. lua_pushstring(L, "n");
  337. lua_pushnumber(L, n+1);
  338. lua_rawset(L, 1); /* t.n = n+1 */
  339. for (; n>=pos; n--) {
  340. lua_rawgeti(L, 1, n);
  341. lua_rawseti(L, 1, n+1); /* t[n+1] = t[n] */
  342. }
  343. lua_pushvalue(L, v);
  344. lua_rawseti(L, 1, pos); /* t[pos] = v */
  345. return 0;
  346. }
  347. static int luaB_tremove (lua_State *L) {
  348. int pos, n;
  349. luaL_checktype(L, 1, "table");
  350. n = lua_getn(L, 1);
  351. pos = luaL_opt_int(L, 2, n);
  352. if (n <= 0) return 0; /* table is "empty" */
  353. lua_rawgeti(L, 1, pos); /* result = t[pos] */
  354. for ( ;pos<n; pos++) {
  355. lua_rawgeti(L, 1, pos+1);
  356. lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */
  357. }
  358. lua_pushstring(L, "n");
  359. lua_pushnumber(L, n-1);
  360. lua_rawset(L, 1); /* t.n = n-1 */
  361. lua_pushnil(L);
  362. lua_rawseti(L, 1, n); /* t[n] = nil */
  363. return 1;
  364. }
  365. /*
  366. ** {======================================================
  367. ** Quicksort
  368. ** (based on `Algorithms in MODULA-3', Robert Sedgewick;
  369. ** Addison-Wesley, 1993.)
  370. */
  371. static void swap (lua_State *L, int i, int j) {
  372. lua_rawgeti(L, 1, i);
  373. lua_rawgeti(L, 1, j);
  374. lua_rawseti(L, 1, i);
  375. lua_rawseti(L, 1, j);
  376. }
  377. static int sort_comp (lua_State *L, int n, int r) {
  378. /* WARNING: the caller (auxsort) must ensure stack space */
  379. int res;
  380. if (!lua_isnil(L, 2)) { /* function? */
  381. lua_pushvalue(L, 2);
  382. if (r) {
  383. lua_rawgeti(L, 1, n); /* a[n] */
  384. lua_pushvalue(L, -3); /* pivot */
  385. }
  386. else {
  387. lua_pushvalue(L, -2); /* pivot */
  388. lua_rawgeti(L, 1, n); /* a[n] */
  389. }
  390. lua_rawcall(L, 2, 1);
  391. res = !lua_isnil(L, -1);
  392. }
  393. else { /* a < b? */
  394. lua_rawgeti(L, 1, n); /* a[n] */
  395. if (r)
  396. res = lua_lessthan(L, -1, -2);
  397. else
  398. res = lua_lessthan(L, -2, -1);
  399. }
  400. lua_pop(L, 1);
  401. return res;
  402. }
  403. static void auxsort (lua_State *L, int l, int u) {
  404. while (l < u) { /* for tail recursion */
  405. int i, j;
  406. luaL_checkstack(L, 4, "array too large");
  407. /* sort elements a[l], a[(l+u)/2] and a[u] */
  408. lua_rawgeti(L, 1, u);
  409. if (sort_comp(L, l, 0)) /* a[u] < a[l]? */
  410. swap(L, l, u);
  411. lua_pop(L, 1);
  412. if (u-l == 1) break; /* only 2 elements */
  413. i = (l+u)/2;
  414. lua_rawgeti(L, 1, i); /* Pivot = a[i] */
  415. if (sort_comp(L, l, 0)) /* a[i]<a[l]? */
  416. swap(L, l, i);
  417. else {
  418. if (sort_comp(L, u, 1)) /* a[u]<a[i]? */
  419. swap(L, i, u);
  420. }
  421. lua_pop(L, 1); /* pop old a[i] */
  422. if (u-l == 2) break; /* only 3 elements */
  423. lua_rawgeti(L, 1, i); /* Pivot */
  424. swap(L, i, u-1); /* put median element as pivot (a[u-1]) */
  425. /* a[l] <= P == a[u-1] <= a[u], only needs to sort from l+1 to u-2 */
  426. i = l; j = u-1;
  427. for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
  428. /* repeat i++ until a[i] >= P */
  429. while (sort_comp(L, ++i, 1))
  430. if (i>u) lua_error(L, "invalid order function for sorting");
  431. /* repeat j-- until a[j] <= P */
  432. while (sort_comp(L, --j, 0))
  433. if (j<l) lua_error(L, "invalid order function for sorting");
  434. if (j<i) break;
  435. swap(L, i, j);
  436. }
  437. swap(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */
  438. /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
  439. /* adjust so that smaller "half" is in [j..i] and larger one in [l..u] */
  440. if (i-l < u-i) {
  441. j=l; i=i-1; l=i+2;
  442. }
  443. else {
  444. j=i+1; i=u; u=j-2;
  445. }
  446. lua_pop(L, 1); /* remove pivot from stack */
  447. auxsort(L, j, i); /* call recursively the smaller one */
  448. } /* repeat the routine for the larger one */
  449. }
  450. static int luaB_sort (lua_State *L) {
  451. int n;
  452. luaL_checktype(L, 1, "table");
  453. n = lua_getn(L, 1);
  454. if (!lua_isnull(L, 2)) /* is there a 2nd argument? */
  455. luaL_checktype(L, 2, "function");
  456. lua_settop(L, 2); /* make sure there is two arguments */
  457. auxsort(L, 1, n);
  458. return 0;
  459. }
  460. /* }====================================================== */
  461. /*
  462. ** {======================================================
  463. ** Deprecated functions to manipulate global environment.
  464. ** =======================================================
  465. */
  466. #define num_deprecated 4
  467. static const struct luaL_reg deprecated_names [num_deprecated] = {
  468. {"foreachvar", luaB_foreach},
  469. {"nextvar", luaB_next},
  470. {"rawgetglobal", luaB_rawget},
  471. {"rawsetglobal", luaB_rawset}
  472. };
  473. #ifdef LUA_DEPRECATETFUNCS
  474. /*
  475. ** call corresponding function inserting `globals' as first argument
  476. */
  477. static int deprecated_func (lua_State *L) {
  478. lua_insert(L, 1); /* upvalue is the function to be called */
  479. lua_getglobals(L);
  480. lua_insert(L, 2); /* table of globals is 1o argument */
  481. lua_rawcall(L, lua_gettop(L)-1, LUA_MULTRET);
  482. return lua_gettop(L); /* return all results */
  483. }
  484. static void deprecated_funcs (lua_State *L) {
  485. int i;
  486. for (i=0; i<num_deprecated; i++) {
  487. lua_pushcfunction(L, deprecated_names[i].func);
  488. lua_pushcclosure(L, deprecated_func, 1);
  489. lua_setglobal(L, deprecated_names[i].name);
  490. }
  491. }
  492. #else
  493. /*
  494. ** gives an explicit error in any attempt to call a deprecated function
  495. */
  496. static int deprecated_func (lua_State *L) {
  497. luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1));
  498. return 0; /* to avoid warnings */
  499. }
  500. static void deprecated_funcs (lua_State *L) {
  501. int i;
  502. for (i=0; i<num_deprecated; i++) {
  503. lua_pushstring(L, deprecated_names[i].name);
  504. lua_pushcclosure(L, deprecated_func, 1);
  505. lua_setglobal(L, deprecated_names[i].name);
  506. }
  507. }
  508. #endif
  509. /* }====================================================== */
  510. static const struct luaL_reg base_funcs[] = {
  511. {LUA_ALERT, luaB__ALERT},
  512. {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE},
  513. {"call", luaB_call},
  514. {"collectgarbage", luaB_collectgarbage},
  515. {"copytagmethods", luaB_copytagmethods},
  516. {"dofile", luaB_dofile},
  517. {"dostring", luaB_dostring},
  518. {"error", luaB_error},
  519. {"foreach", luaB_foreach},
  520. {"foreachi", luaB_foreachi},
  521. {"getglobal", luaB_getglobal},
  522. {"gettagmethod", luaB_gettagmethod},
  523. {"globals", luaB_globals},
  524. {"newtag", luaB_newtag},
  525. {"next", luaB_next},
  526. {"print", luaB_print},
  527. {"rawget", luaB_rawget},
  528. {"rawset", luaB_rawset},
  529. {"rawgettable", luaB_rawget}, /* for compatibility */
  530. {"rawsettable", luaB_rawset}, /* for compatibility */
  531. {"setglobal", luaB_setglobal},
  532. {"settag", luaB_settag},
  533. {"settagmethod", luaB_settagmethod},
  534. {"tag", luaB_tag},
  535. {"tonumber", luaB_tonumber},
  536. {"tostring", luaB_tostring},
  537. {"type", luaB_type},
  538. {"assert", luaB_assert},
  539. {"getn", luaB_getn},
  540. {"sort", luaB_sort},
  541. {"tinsert", luaB_tinsert},
  542. {"tremove", luaB_tremove}
  543. };
  544. void lua_baselibopen (lua_State *L) {
  545. luaL_openl(L, base_funcs);
  546. lua_pushstring(L, LUA_VERSION);
  547. lua_setglobal(L, "_VERSION");
  548. deprecated_funcs(L);
  549. }