我把tests/tarray 这个demo里的代码简化了一下,只保留成这样:
-
#include "tarray.h"
-
Array array;
-
int abc(void)
-
{
-
lua_open();
-
return 0;
-
}
-
$ cat tarray.h
-
typedef struct Array Array;
-
struct Array
-
{
-
int a;
-
};
-
-
extern Array array
-
$ cat tarray.pkg
-
$#include "tarray.h"
-
-
struct Array
-
{
-
int a;
-
};
-
-
extern Array array
processpg -o tarraybind.c tarray.pkg,生成一个tarraybind.c,不到100行。去掉调试宏就更少了。很容易看。
-
/*
-
** Lua binding: tarray
-
** Generated automatically by tolua++-1.0.92 on 05/25/15 14:39:52.
-
*/
-
-
#ifndef __cplusplus
-
#include "stdlib.h"
-
#endif
-
#include "string.h"
-
-
#include "tolua++.h"
-
-
/* Exported function */
-
TOLUA_API int tolua_tarray_open (lua_State* tolua_S);
-
-
#include "tarray.h"
-
-
/* function to register type */
-
static void tolua_reg_types (lua_State* tolua_S)
-
{
-
tolua_usertype(tolua_S,"Array");
-
}
-
-
/* get function: a of class Array */
-
#ifndef TOLUA_DISABLE_tolua_get_Array_a
-
static int tolua_get_Array_a(lua_State* tolua_S)
-
{
-
Array* self = (Array*) tolua_tousertype(tolua_S,1,0);
-
#ifndef TOLUA_RELEASE
-
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'a'",NULL);
-
#endif
-
tolua_pushnumber(tolua_S,(lua_Number)self->a);
-
return 1;
-
}
-
#endif //#ifndef TOLUA_DISABLE
-
-
/* set function: a of class Array */
-
#ifndef TOLUA_DISABLE_tolua_set_Array_a
-
static int tolua_set_Array_a(lua_State* tolua_S)
-
{
-
Array* self = (Array*) tolua_tousertype(tolua_S,1,0);
-
#ifndef TOLUA_RELEASE
-
tolua_Error tolua_err;
-
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'a'",NULL);
-
if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
-
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
-
#endif
-
self->a = ((int) tolua_tonumber(tolua_S,2,0))
-
;
-
return 0;
-
}
-
#endif //#ifndef TOLUA_DISABLE
-
-
/* get function: array */
-
#ifndef TOLUA_DISABLE_tolua_get_array
-
static int tolua_get_array(lua_State* tolua_S)
-
{
-
tolua_pushusertype(tolua_S,(void*)&array,"Array");
-
return 1;
-
}
-
#endif //#ifndef TOLUA_DISABLE
-
-
/* set function: array */
-
#ifndef TOLUA_DISABLE_tolua_set_array
-
static int tolua_set_array(lua_State* tolua_S)
-
{
-
#ifndef TOLUA_RELEASE
-
tolua_Error tolua_err;
-
if ((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Array",0,&tolua_err)))
-
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
-
#endif
-
array = *((Array*) tolua_tousertype(tolua_S,2,0))
-
;
-
return 0;
-
}
-
#endif //#ifndef TOLUA_DISABLE
-
-
/* Open function */
-
TOLUA_API int tolua_tarray_open (lua_State* tolua_S)
-
{
-
tolua_open(tolua_S);
-
tolua_reg_types(tolua_S);
-
tolua_module(tolua_S,NULL,1);
-
tolua_beginmodule(tolua_S,NULL);
-
tolua_cclass(tolua_S,"Array","Array","",NULL);
-
tolua_beginmodule(tolua_S,"Array");
-
tolua_variable(tolua_S,"a",tolua_get_Array_a,tolua_set_Array_a);
-
tolua_endmodule(tolua_S);
-
tolua_variable(tolua_S,"array",tolua_get_array,tolua_set_array);
-
tolua_endmodule(tolua_S);
-
return 1;
-
}
-
-
-
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
-
TOLUA_API int luaopen_tarray (lua_State* tolua_S) {
-
return tolua_tarray_open(tolua_S);
-
};
-
#endif
阅读(2367) | 评论(0) | 转发(0) |