小编Pau*_*ner的帖子

为什么内部Lua字符串以他们的方式存储?

我想要一个简单的字符串表,它将存储一堆常量,我想"嘿!Lua那样做,让我使用一些函数!"

这主要是在lstring.h/lstring.c文件中(我使用的是5.2)

我将首先展示我很好奇的代码.它来自lobject.h

/*
** Header for string value; string bytes follow the end of this structure
*/
typedef union TString {
  L_Umaxalign dummy;  /* ensures maximum alignment for strings */
  struct {
    CommonHeader;
    lu_byte reserved;
    unsigned int hash;
    size_t len;  /* number of characters in string */
  } tsv;
} TString;


/* get the actual string (array of bytes) from a TString */
#define getstr(ts)  cast(const char *, (ts) + 1)

/* get the actual string (array of bytes) …
Run Code Online (Sandbox Code Playgroud)

c string lua struct

8
推荐指数
1
解决办法
1450
查看次数

标签 统计

c ×1

lua ×1

string ×1

struct ×1