mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 19:13:07 +00:00
* update to lua 5.4.0-rc1 * remove LUA_ERRGCMM * use age bits for shared * remove unused lbitlib.c * use luaV_fastget * fix #1174 * suspend函数tailcall优化 * 防止没有session导致未调用suspend * luaH_setint check shared (#1184) * set LUA_GCGEN by default * fix #1174 (#1186) checkshared in sweeplist * update to lua 5.4 rc2 * update to lua 5.4 rc4 * move skynet.profile into snlua * Use lua_sethook to interrupt tight loops * remove lua_checksig * critical condition for signals * update to lua 5.4 released * lua 5.4 bugfix * update lua bugfix * fix lua_sharestring (#1224) * update lua * update lua 5.4 * update README * add skynet.select * add test * test error & discard * yield session * request error has no error message * add timeout to skynet.select * bugfix * for lua 5.4 * new version * bugfix * bugfix * use if instead of while * make local * yield in select for * update lua 5.4.1 * change lua version (#1245) Co-authored-by: xiaojin <xiaojin@onemt.com.cn> * update lua version number Co-authored-by: hong <hongling0@gmail.com> Co-authored-by: hong <hongling-0@qq.com> Co-authored-by: 风---自由 <996442717qqcom@gmail.com> Co-authored-by: xiaojin <xiaojin@onemt.com.cn>
69 lines
1.3 KiB
C
69 lines
1.3 KiB
C
/*
|
|
** $Id: lzio.c $
|
|
** Buffered streams
|
|
** See Copyright Notice in lua.h
|
|
*/
|
|
|
|
#define lzio_c
|
|
#define LUA_CORE
|
|
|
|
#include "lprefix.h"
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "lua.h"
|
|
|
|
#include "llimits.h"
|
|
#include "lmem.h"
|
|
#include "lstate.h"
|
|
#include "lzio.h"
|
|
|
|
|
|
int luaZ_fill (ZIO *z) {
|
|
size_t size;
|
|
lua_State *L = z->L;
|
|
const char *buff;
|
|
lua_unlock(L);
|
|
buff = z->reader(L, z->data, &size);
|
|
lua_lock(L);
|
|
if (buff == NULL || size == 0)
|
|
return EOZ;
|
|
z->n = size - 1; /* discount char being returned */
|
|
z->p = buff;
|
|
return cast_uchar(*(z->p++));
|
|
}
|
|
|
|
|
|
void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
|
|
z->L = L;
|
|
z->reader = reader;
|
|
z->data = data;
|
|
z->n = 0;
|
|
z->p = NULL;
|
|
}
|
|
|
|
|
|
/* --------------------------------------------------------------- read --- */
|
|
size_t luaZ_read (ZIO *z, void *b, size_t n) {
|
|
while (n) {
|
|
size_t m;
|
|
if (z->n == 0) { /* no bytes in buffer? */
|
|
if (luaZ_fill(z) == EOZ) /* try to read more */
|
|
return n; /* no more input; return number of missing bytes */
|
|
else {
|
|
z->n++; /* luaZ_fill consumed first byte; put it back */
|
|
z->p--;
|
|
}
|
|
}
|
|
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
|
|
memcpy(b, z->p, m);
|
|
z->n -= m;
|
|
z->p += m;
|
|
b = (char *)b + m;
|
|
n -= m;
|
|
}
|
|
return 0;
|
|
}
|
|
|