MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / luaO_chunkid

Function luaO_chunkid

src/Chain/libraries/glua/lobject.cpp:442–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440#define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) )
441
442void luaO_chunkid(char *out, const char *source, size_t bufflen) {
443 size_t l = strlen(source);
444 if (*source == '=') { /* 'literal' source */
445 if (l <= bufflen) /* small enough? */
446 memcpy(out, source + 1, l * sizeof(char));
447 else { /* truncate it */
448 addstr(out, source + 1, bufflen - 1);
449 *out = '\0';
450 }
451 }
452 else if (*source == '@') { /* file name */
453 if (l <= bufflen) /* small enough? */
454 memcpy(out, source + 1, l * sizeof(char));
455 else { /* add '...' before rest of name */
456 addstr(out, RETS, LL(RETS));
457 bufflen -= LL(RETS);
458 memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
459 }
460 }
461 else { /* string; format as [string "source"] */
462 const char *nl = strchr(source, '\n'); /* find first new line (if any) */
463 addstr(out, PRE, LL(PRE)); /* add prefix */
464 bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
465 if (l < bufflen && nl == nullptr) { /* small one-line source? */
466 addstr(out, source, l); /* keep it */
467 }
468 else {
469 if (nl != nullptr) l = nl - source; /* stop at first newline */
470 if (l > bufflen) l = bufflen;
471 addstr(out, source, l);
472 addstr(out, RETS, LL(RETS));
473 }
474 memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
475 }
476}
477

Callers 2

funcinfoFunction · 0.85
luaG_addinfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected