关键词搜索

源码搜索 ×
×

C++和lua都要了解下

发布2022-06-26浏览855次

详情内容

C++比较熟悉了,但lua不太熟,最近看redis源码,对这个语言有点兴趣,其实,不掌握也行,能看大C++的加载即可:

  1. int luaZ_fill (ZIO *z) {
  2. size_t size;
  3. lua_State *L = z->L;
  4. const char *buff;
  5. lua_unlock(L);
  6. buff = z->reader(L, z->data, &size);
  7. lua_lock(L);
  8. if (buff == NULL || size == 0) return EOZ;
  9. z->n = size - 1;
  10. z->p = buff;
  11. return char2int(*(z->p++));
  12. }
  13. int luaZ_lookahead (ZIO *z) {
  14. if (z->n == 0) {
  15. if (luaZ_fill(z) == EOZ)
  16. return EOZ;
  17. else {
  18. z->n++; /* luaZ_fill removed first byte; put back it */
  19. z->p--;
  20. }
  21. }
  22. return char2int(*z->p);
  23. }
  24. void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
  25. z->L = L;
  26. z->reader = reader;
  27. z->data = data;
  28. z->n = 0;
  29. z->p = NULL;
  30. }
  31. /* --------------------------------------------------------------- read --- */
  32. size_t luaZ_read (ZIO *z, void *b, size_t n) {
  33. while (n) {
  34. size_t m;
  35. if (luaZ_lookahead(z) == EOZ)
  36. return n; /* return number of missing bytes */
  37. m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
  38. memcpy(b, z->p, m);
  39. z->n -= m;
  40. z->p += m;
  41. b = (char *)b + m;
  42. n -= m;
  43. }
  44. return 0;
  45. }
  46. /* ------------------------------------------------------------------------ */
  47. char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
  48. if (n > buff->buffsize) {
  49. if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
  50. luaZ_resizebuffer(L, buff, n);
  51. }
  52. return buff->buffer;
  53. }

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载