Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56000
  • 博文数量: 13
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2015-04-26 15:04
文章分类

全部博文(13)

文章存档

2015年(13)

我的朋友

分类: Android平台

2015-05-25 15:03:36

  我把tests/tarray 这个demo里的代码简化了一下,只保留成这样:

点击(此处)折叠或打开

  1. #include "tarray.h"
  2. Array array;
  3. int abc(void)
  4. {
  5.         lua_open();
  6.         return 0;
  7. }

点击(此处)折叠或打开

  1. $ cat tarray.h
  2. typedef struct Array Array;
  3. struct Array
  4. {
  5.  int a;
  6. };

  7. extern Array array

点击(此处)折叠或打开

  1. $ cat tarray.pkg
  2. $#include "tarray.h"

  3. struct Array
  4. {
  5.  int a;
  6. };

  7. extern Array array
processpg -o tarraybind.c tarray.pkg,生成一个tarraybind.c,不到100行。去掉调试宏就更少了。很容易看。

点击(此处)折叠或打开

  1. /*
  2. ** Lua binding: tarray
  3. ** Generated automatically by tolua++-1.0.92 on 05/25/15 14:39:52.
  4. */

  5. #ifndef __cplusplus
  6. #include "stdlib.h"
  7. #endif
  8. #include "string.h"

  9. #include "tolua++.h"

  10. /* Exported function */
  11. TOLUA_API int tolua_tarray_open (lua_State* tolua_S);

  12. #include "tarray.h"

  13. /* function to register type */
  14. static void tolua_reg_types (lua_State* tolua_S)
  15. {
  16. tolua_usertype(tolua_S,"Array");
  17. }

  18. /* get function: a of class Array */
  19. #ifndef TOLUA_DISABLE_tolua_get_Array_a
  20. static int tolua_get_Array_a(lua_State* tolua_S)
  21. {
  22. Array* self = (Array*) tolua_tousertype(tolua_S,1,0);
  23. #ifndef TOLUA_RELEASE
  24. if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'a'",NULL);
  25. #endif
  26. tolua_pushnumber(tolua_S,(lua_Number)self->a);
  27. return 1;
  28. }
  29. #endif //#ifndef TOLUA_DISABLE

  30. /* set function: a of class Array */
  31. #ifndef TOLUA_DISABLE_tolua_set_Array_a
  32. static int tolua_set_Array_a(lua_State* tolua_S)
  33. {
  34. Array* self = (Array*) tolua_tousertype(tolua_S,1,0);
  35. #ifndef TOLUA_RELEASE
  36. tolua_Error tolua_err;
  37. if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'a'",NULL);
  38. if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
  39. tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
  40. #endif
  41. self->a = ((int) tolua_tonumber(tolua_S,2,0))
  42. ;
  43. return 0;
  44. }
  45. #endif //#ifndef TOLUA_DISABLE

  46. /* get function: array */
  47. #ifndef TOLUA_DISABLE_tolua_get_array
  48. static int tolua_get_array(lua_State* tolua_S)
  49. {
  50. tolua_pushusertype(tolua_S,(void*)&array,"Array");
  51. return 1;
  52. }
  53. #endif //#ifndef TOLUA_DISABLE

  54. /* set function: array */
  55. #ifndef TOLUA_DISABLE_tolua_set_array
  56. static int tolua_set_array(lua_State* tolua_S)
  57. {
  58. #ifndef TOLUA_RELEASE
  59. tolua_Error tolua_err;
  60. if ((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Array",0,&tolua_err)))
  61. tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
  62. #endif
  63. array = *((Array*) tolua_tousertype(tolua_S,2,0))
  64. ;
  65. return 0;
  66. }
  67. #endif //#ifndef TOLUA_DISABLE

  68. /* Open function */
  69. TOLUA_API int tolua_tarray_open (lua_State* tolua_S)
  70. {
  71. tolua_open(tolua_S);
  72. tolua_reg_types(tolua_S);
  73. tolua_module(tolua_S,NULL,1);
  74. tolua_beginmodule(tolua_S,NULL);
  75. tolua_cclass(tolua_S,"Array","Array","",NULL);
  76. tolua_beginmodule(tolua_S,"Array");
  77. tolua_variable(tolua_S,"a",tolua_get_Array_a,tolua_set_Array_a);
  78. tolua_endmodule(tolua_S);
  79. tolua_variable(tolua_S,"array",tolua_get_array,tolua_set_array);
  80. tolua_endmodule(tolua_S);
  81. return 1;
  82. }


  83. #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
  84. TOLUA_API int luaopen_tarray (lua_State* tolua_S) {
  85. return tolua_tarray_open(tolua_S);
  86. };
  87. #endif

阅读(2292) | 评论(0) | 转发(0) |
0

上一篇:小试tolua++ 0.6

下一篇:cygwin的点滴 0.5

给主人留下些什么吧!~~