** options to control endianess and alignment */
| 146 | ** options to control endianess and alignment |
| 147 | */ |
| 148 | static void controloptions (lua_State *L, int opt, const char **fmt, |
| 149 | Header *h) { |
| 150 | switch (opt) { |
| 151 | case ' ': return; /* ignore white spaces */ |
| 152 | case '>': h->endian = BIG; return; |
| 153 | case '<': h->endian = LITTLE; return; |
| 154 | case '!': { |
| 155 | int a = getnum(L, fmt, MAXALIGN); |
| 156 | if (!isp2(a)) |
| 157 | luaL_error(L, "alignment %d is not a power of 2", a); |
| 158 | h->align = a; |
| 159 | return; |
| 160 | } |
| 161 | default: { |
| 162 | const char *msg = lua_pushfstring(L, "invalid format option '%c'", opt); |
| 163 | luaL_argerror(L, 1, msg); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | |
| 169 | static void putinteger (lua_State *L, luaL_Buffer *b, int arg, int endian, |
no test coverage detected