diff options
author | chai <chaifix@163.com> | 2021-11-08 01:17:11 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-08 01:17:11 +0800 |
commit | efce5b6bd5c9d4f8214a71e0f7a7c35751710a4c (patch) | |
tree | 0789475ded5c377667165a3ddb047ca6703bcf33 /ThirdParty/toluapp/src/tests | |
parent | ed78df90944bbe6b7de7308bda2bf3a7f1bc3de6 (diff) |
+ tolua
+ lpeg
Diffstat (limited to 'ThirdParty/toluapp/src/tests')
34 files changed, 2703 insertions, 0 deletions
diff --git a/ThirdParty/toluapp/src/tests/SCsub b/ThirdParty/toluapp/src/tests/SCsub new file mode 100644 index 0000000..2a2fb26 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/SCsub @@ -0,0 +1,18 @@ +Import('env') +env_tests = env.Copy() + +env_tests.LuaBinding('tclassbind.cpp', 'tclass.pkg', 'tclass', use_own=1, use_typeid=1) + +env_tests.Append(CXXFLAGS='-DTOLUA_API="extern \\\"C\\\""') + +test_class_so = env_tests.SharedLibrary('tclass', ['tclassbind.cpp'], + LIBS=['$tolua_lib']+env['LIBS'], ) + +env_tests.Append(LIBPATH=".") + +test_class = env_tests.Program('tclass', ['tclass.cpp'], + LIBS=env['LIBS']+['tclass']+['$tolua_lib'], ) + + + +env.test_targets = [test_class] diff --git a/ThirdParty/toluapp/src/tests/tarray.c b/ThirdParty/toluapp/src/tests/tarray.c new file mode 100644 index 0000000..e69bcf4 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tarray.c @@ -0,0 +1,45 @@ +#include "lualib.h" +#include "lauxlib.h" + +#include "tarray.h" + + +int a[10] = {1,2,3,4,5,6,7,8,9,10}; +Point p[10] = {{0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10}}; +Point* pp[10]; + +int ma[10]; +Point mp[10]; +Point* mpp[10]; + +Array array; +Array* parray = &array; + +int main (void) +{ + int tolua_tarray_open (lua_State*); + lua_State* L = lua_open(); + int i; + + for (i=0; i<10; ++i) + { + pp[i] = &p[i]; + + ma[i] = a[i]; + mp[i] = p[i]; + mpp[i] = pp[i]; + + array.a[i] = a[i]; + array.p[i] = p[i]; + array.pp[i] = pp[i]; + } + + luaopen_base(L); + tolua_tarray_open(L); + + lua_dofile(L,"tarray.lua"); + + lua_close(L); + return 0; +} + diff --git a/ThirdParty/toluapp/src/tests/tarray.h b/ThirdParty/toluapp/src/tests/tarray.h new file mode 100644 index 0000000..6964ef7 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tarray.h @@ -0,0 +1,28 @@ + +typedef struct Point Point; +struct Point +{ + float x; + float y; +}; + + +extern int a[10]; +extern Point p[10]; +extern Point* pp[10]; + + +extern int ma[10]; +extern Point mp[10]; +extern Point* mpp[10]; + +typedef struct Array Array; +struct Array +{ + int a[10]; + Point p[10]; + Point* pp[10]; +}; + +extern Array array; +extern Array* parray; diff --git a/ThirdParty/toluapp/src/tests/tarray.lua b/ThirdParty/toluapp/src/tests/tarray.lua new file mode 100644 index 0000000..2a8a4ce --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tarray.lua @@ -0,0 +1,37 @@ +for i=1,10 do + assert(a[i]==i) +end + +for i=2,10 do + assert(p[i-1].y==p[i].x) +end + +for i=1,10 do + assert(M.a[i]==i) +end + +for i=2,10 do + assert(M.p[i-1].y==M.p[i].x) +end + +for i=1,10 do + assert(pp[i].x==M.p[i].x and p[i].y == M.pp[i].y) +end + +for i=1,10 do + assert(array.a[i] == parray.a[i]) + assert(array.p[i].x == parray.pp[i].x and array.p[i].y == parray.pp[i].y) +end + +for i=1,10 do + array.a[i] = a[10-i+1] + M.a[i] = 10-i+1 + assert(array.a[i]==M.a[i]) +end + +for i=2,10 do + array.p[i] = array.pp[1] + assert(array.p[i].x==0 and array.p[i].y==1) +end + +print("Array test OK") diff --git a/ThirdParty/toluapp/src/tests/tarray.pkg b/ThirdParty/toluapp/src/tests/tarray.pkg new file mode 100644 index 0000000..32859c9 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tarray.pkg @@ -0,0 +1,29 @@ +$#include "tarray.h" + +struct Point +{ + float x; + float y; +}; + + +extern int a[10]; +extern const Point p[10]; +extern Point* pp[10]; + + +module M { +extern int ma[10]@a; +extern const Point mp[10]@p; +extern Point* mpp[10]@pp; +} + +struct Array +{ + int a[10]; + Point p[10]; + Point* pp[10]; +}; + +extern Array array; +extern Array* parray; diff --git a/ThirdParty/toluapp/src/tests/tarraybind.c b/ThirdParty/toluapp/src/tests/tarraybind.c new file mode 100644 index 0000000..4a9e0ed --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tarraybind.c @@ -0,0 +1,504 @@ +/* +** Lua binding: tarray +** Generated automatically by tolua 5.0a-CDLVS2 on 08/08/03 17:06:22. +*/ + +#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 release collected object via destructor */ +#ifdef __cplusplus + +static int tolua_collect_Point (lua_State* tolua_S) +{ + Point* self = (Point*) tolua_tousertype(tolua_S,1,0); + delete self; + return 0; +} +#endif + + +/* function to register type */ +static void tolua_reg_types (lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"Array"); + tolua_usertype(tolua_S,"Point"); +} + +/* get function: x of class Point */ +static int tolua_get_Point_x(lua_State* tolua_S) +{ + Point* self = (Point*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'x'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->x); + return 1; +} + +/* set function: x of class Point */ +static int tolua_set_Point_x(lua_State* tolua_S) +{ + Point* self = (Point*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'x'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->x = ((float) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: y of class Point */ +static int tolua_get_Point_y(lua_State* tolua_S) +{ + Point* self = (Point*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'y'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->y); + return 1; +} + +/* set function: y of class Point */ +static int tolua_set_Point_y(lua_State* tolua_S) +{ + Point* self = (Point*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'y'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->y = ((float) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: a */ +static int tolua_get_tarray_a(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushnumber(tolua_S,(double)a[tolua_index]); + return 1; +} + +/* set function: a */ +static int tolua_set_tarray_a(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + a[tolua_index] = ((int) tolua_tonumber(tolua_S,3,0)); + return 0; +} + +/* get function: p */ +static int tolua_get_tarray_p(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)&p[tolua_index],"const Point"); + return 1; +} + +/* get function: pp */ +static int tolua_get_tarray_pp(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)pp[tolua_index],"Point"); + return 1; +} + +/* set function: pp */ +static int tolua_set_tarray_pp(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + pp[tolua_index] = ((Point*) tolua_tousertype(tolua_S,3,0)); + return 0; +} + +/* get function: ma */ +static int tolua_get_tarray_M_ma(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushnumber(tolua_S,(double)ma[tolua_index]); + return 1; +} + +/* set function: ma */ +static int tolua_set_tarray_M_ma(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + ma[tolua_index] = ((int) tolua_tonumber(tolua_S,3,0)); + return 0; +} + +/* get function: mp */ +static int tolua_get_tarray_M_mp(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)&mp[tolua_index],"const Point"); + return 1; +} + +/* get function: mpp */ +static int tolua_get_tarray_M_mpp(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)mpp[tolua_index],"Point"); + return 1; +} + +/* set function: mpp */ +static int tolua_set_tarray_M_mpp(lua_State* tolua_S) +{ + int tolua_index; +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + mpp[tolua_index] = ((Point*) tolua_tousertype(tolua_S,3,0)); + return 0; +} + +/* get function: a of class Array */ +static int tolua_get_tarray_Array_a(lua_State* tolua_S) +{ + int tolua_index; + Array* self; + lua_pushstring(tolua_S,".self"); + lua_rawget(tolua_S,1); + self = (Array*) lua_touserdata(tolua_S,-1); +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->a[tolua_index]); + return 1; +} + +/* set function: a of class Array */ +static int tolua_set_tarray_Array_a(lua_State* tolua_S) +{ + int tolua_index; + Array* self; + lua_pushstring(tolua_S,".self"); + lua_rawget(tolua_S,1); + self = (Array*) lua_touserdata(tolua_S,-1); +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + self->a[tolua_index] = ((int) tolua_tonumber(tolua_S,3,0)); + return 0; +} + +/* get function: p of class Array */ +static int tolua_get_tarray_Array_p(lua_State* tolua_S) +{ + int tolua_index; + Array* self; + lua_pushstring(tolua_S,".self"); + lua_rawget(tolua_S,1); + self = (Array*) lua_touserdata(tolua_S,-1); +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)&self->p[tolua_index],"Point"); + return 1; +} + +/* set function: p of class Array */ +static int tolua_set_tarray_Array_p(lua_State* tolua_S) +{ + int tolua_index; + Array* self; + lua_pushstring(tolua_S,".self"); + lua_rawget(tolua_S,1); + self = (Array*) lua_touserdata(tolua_S,-1); +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + self->p[tolua_index] = *((Point*) tolua_tousertype(tolua_S,3,0)); + return 0; +} + +/* get function: pp of class Array */ +static int tolua_get_tarray_Array_pp(lua_State* tolua_S) +{ + int tolua_index; + Array* self; + lua_pushstring(tolua_S,".self"); + lua_rawget(tolua_S,1); + self = (Array*) lua_touserdata(tolua_S,-1); +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)self->pp[tolua_index],"Point"); + return 1; +} + +/* set function: pp of class Array */ +static int tolua_set_tarray_Array_pp(lua_State* tolua_S) +{ + int tolua_index; + Array* self; + lua_pushstring(tolua_S,".self"); + lua_rawget(tolua_S,1); + self = (Array*) lua_touserdata(tolua_S,-1); +#ifndef TOLUA_RELEASE + { + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err); + } +#endif + tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1; +#ifndef TOLUA_RELEASE + if (tolua_index<0 || tolua_index>=10) + tolua_error(tolua_S,"array indexing out of range.",NULL); +#endif + self->pp[tolua_index] = ((Point*) tolua_tousertype(tolua_S,3,0)); + return 0; +} + +/* get function: array */ +static int tolua_get_array(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)&array,"Array"); + return 1; +} + +/* set function: array */ +static int tolua_set_array(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!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; +} + +/* get function: parray */ +static int tolua_get_parray_ptr(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)parray,"Array"); + return 1; +} + +/* set function: parray */ +static int tolua_set_parray_ptr(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"Array",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + parray = ((Array*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* 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); +#ifdef __cplusplus + tolua_cclass(tolua_S,"Point","Point","",tolua_collect_Point); +#else + tolua_cclass(tolua_S,"Point","Point","",NULL); +#endif + tolua_beginmodule(tolua_S,"Point"); + tolua_variable(tolua_S,"x",tolua_get_Point_x,tolua_set_Point_x); + tolua_variable(tolua_S,"y",tolua_get_Point_y,tolua_set_Point_y); + tolua_endmodule(tolua_S); + tolua_array(tolua_S,"a",tolua_get_tarray_a,tolua_set_tarray_a); + tolua_array(tolua_S,"p",tolua_get_tarray_p,NULL); + tolua_array(tolua_S,"pp",tolua_get_tarray_pp,tolua_set_tarray_pp); + tolua_module(tolua_S,"M",1); + tolua_beginmodule(tolua_S,"M"); + tolua_array(tolua_S,"a",tolua_get_tarray_M_ma,tolua_set_tarray_M_ma); + tolua_array(tolua_S,"p",tolua_get_tarray_M_mp,NULL); + tolua_array(tolua_S,"pp",tolua_get_tarray_M_mpp,tolua_set_tarray_M_mpp); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"Array","Array","",NULL); + tolua_beginmodule(tolua_S,"Array"); + tolua_array(tolua_S,"a",tolua_get_tarray_Array_a,tolua_set_tarray_Array_a); + tolua_array(tolua_S,"p",tolua_get_tarray_Array_p,tolua_set_tarray_Array_p); + tolua_array(tolua_S,"pp",tolua_get_tarray_Array_pp,tolua_set_tarray_Array_pp); + tolua_endmodule(tolua_S); + tolua_variable(tolua_S,"array",tolua_get_array,tolua_set_array); + tolua_variable(tolua_S,"parray",tolua_get_parray_ptr,tolua_set_parray_ptr); + tolua_endmodule(tolua_S); + return 1; +} diff --git a/ThirdParty/toluapp/src/tests/tclass.cpp b/ThirdParty/toluapp/src/tests/tclass.cpp new file mode 100644 index 0000000..02ca770 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tclass.cpp @@ -0,0 +1,32 @@ +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} + +#include "tclass.h" + +//Test::Tst_A* Test::Tst_A::last; +//Test::Tst_B* Test::Tst_B::last; +//Test::Tst_C* Test::Tst_C::last; + +extern "C" { + int tolua_tclass_open (lua_State*); +} + +int main () +{ + Test::Tst_B* b = new Test::Tst_B; // instance used in Lua code + + lua_State* L = lua_open(); + luaL_openlibs(L); + tolua_tclass_open(L); + + luaL_dofile(L,"tclass.lua"); + + lua_close(L); + + delete b; + return 0; +} + diff --git a/ThirdParty/toluapp/src/tests/tclass.h b/ThirdParty/toluapp/src/tests/tclass.h new file mode 100644 index 0000000..de64ae6 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tclass.h @@ -0,0 +1,121 @@ +#ifndef TCLASS_H +#define TCLASS_H + +#include <stdio.h> + +namespace Test { + +class Tst_Dummy +{ +}; + +class Tst_A +{ + + int number; +public: + static Tst_A* last; + Tst_A () {last = this;} + virtual char* a () { return "A"; } + class Tst_AA + { + public: + Tst_AA () {} + ~Tst_AA () { } + char* aa () { return "AA"; } + }; + class Tst_BB : public Tst_AA + { + public: + Tst_BB () {} + ~Tst_BB () {} + Tst_AA* Base () { return this; } + }; + + void set_number(int p_number) { number = p_number;}; + int get_number() {return number*2;}; + + virtual ~Tst_A() {}; +}; + +class Tst_B : public Tst_A +{ +public: + static Tst_B* last; + Tst_B () {last = this;} + virtual char* b () { return "B"; } + + static Tst_A* create() {return new Tst_B;}; + static void* create_void() {return new Tst_B;}; + + virtual ~Tst_B() {}; +}; + +class Tst_C : public Tst_B +{ + int i; +public: + static Tst_C* last; + Tst_C (int n) : i(n) {last = this;} + virtual ~Tst_C () { printf("deleting C: %d\n",i); } + virtual char* c () { return "C"; } +}; + +inline Tst_A::Tst_AA* Tst_create_aa () +{ + return new Tst_A::Tst_AA(); +} + +inline bool Tst_is_aa (Tst_A::Tst_AA* obj) +{ + return true; +} + +class Tst_E { + void* ptr; + +public: + enum Pete { + ONE, + TWO, + } pete; + + void get_pete(Pete p) {}; + + template <class T> + T get_t() {T a=0; return a;}; + + Tst_E& operator+(const Tst_E& rvalue) {return *this;}; + + void pars(int a=0, int b=0) {}; + void get_pointer(void* a) {}; + + Tst_A a; + + void set_ptr(void* p_ptr) { + printf("this is %p, ptr is %p\n", this, p_ptr); + ptr = p_ptr; + }; + void* get_ptr() {return ptr;}; + + Tst_E(int) {}; +}; + +class Tst_Outside { + +public: + + Tst_Outside() {}; +}; + +}; // end of namespace + + +static void outside_func(Test::Tst_Outside* p_out, lua_State* ls) { + + if (p_out) printf("method!\n"); + else printf("static!\n"); + //printf("luastate: %i\n", ls); +}; + +#endif diff --git a/ThirdParty/toluapp/src/tests/tclass.lua b/ThirdParty/toluapp/src/tests/tclass.lua new file mode 100644 index 0000000..6dea5e9 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tclass.lua @@ -0,0 +1,131 @@ +if not Test then + local loadlib + if not package then + loadlib = _G['loadlib'] + else + loadlib = package.loadlib + end + f, e, eo = loadlib("./libtclass.so", "luaopen_tclass") + if f then + f() + else + print(eo, e) + os.exit() + end +end + +a = {} +rawset(a, ".c_instance", "something") + +function hello() + + print("hello world") +end + +rawset(Test.B, "hello", hello) + +-- type convertion tests +--print(Test.A) +--print(tolua.type(Test.A.last)) +--assert(tolua.type(Test.A.last) == 'Test::Tst_A') -- first time the object is mapped +--assert(tolua.type(Test.B.last) == 'Test::Tst_B') -- type convertion to specialized type +--assert(tolua.type(Test.A.last) == 'Test::Tst_B') -- no convertion: obj already mapped as B + + +local a = Test.A:new() +assert(tolua.type(Test.A.last) == 'Test::Tst_A') -- no type convertion: same type +local b = Test.B:new() +assert(tolua.type(Test.A.last) == 'Test::Tst_B') -- no convertion: obj already mapped as B +local c = Test.luaC:new(0) +assert(tolua.type(Test.A.last) == 'Test::Tst_C') -- no convertion: obj already mapped as C +assert(tolua.type(Test.luaC.last) == 'Test::Tst_C') + +local aa = Test.A.AA:new() +local bb = Test.A.BB:new() +local xx = Test.create_aa() + +-- method calling tests +assert(a:a() == 'A') +assert(b:a() == 'A') +assert(b:b() == 'B') +assert(c:a() == 'A') +assert(c:b() == 'B') +assert(c:c() == 'C') +assert(aa:aa() == 'AA') +assert(bb:aa() == bb:Base():aa()) +assert(xx:aa() == 'AA') +assert(Test.is_aa(bb) == true) + +-- test ownershipping handling +-- should delete objects: 6 7 8 9 10 (it may vary!) +local set = {} +for i=1,10 do + local c = Test.luaC:new(i) + if i>5 then + tolua.takeownership(c) + end + --set[i] = c +end + + + +e = Test.B:new_local() + +print("e is type "..tolua.type(e)) +print("ae is type "..tolua.type(ae)) + +--e:delete() + +b:hello() + +---------- +local out = Test.Outside:new_local() +out:outside() +Test.Outside:outside_static(nil) + + +print "***** cast" +local acast = Test.B:create_void() +print("type is "..tolua.type(acast)) +local bcast = tolua.cast(acast, "Test::Tst_B") +print("bcast is "..tostring(bcast)) +print("type is "..tolua.type(bcast)) +print(bcast:b()) + +-- test properies +local n = 7 +a.number = n +assert(a.number == n*2) + +-- constructors +print(getmetatable(Test.A)) +print(getmetatable(Test.B)) +print(getmetatable(Test.E)) + +local a = Test.A() +local b = Test.B() +local e = Test.E(5) +--print(e+5) +print(tostring(getmetatable(Test.B).__call)) +print(tostring(Test.B.__call)) +print(tostring(Test.B.__call(Test.B))) +print(tolua.type(b)) + +e:set_ptr(e) +local ve = tolua.cast(e:get_ptr(), "Test::Tst_E") +ve:set_ptr(ve) + +print"1" +Test.A.pete = {} +print"2" +table.insert(Test.A.pete, a) +print"3" + + +for i=1,100000 do + la = {} + tolua.inherit(la, a) +end + +print("Class test OK") + diff --git a/ThirdParty/toluapp/src/tests/tclass.pkg b/ThirdParty/toluapp/src/tests/tclass.pkg new file mode 100644 index 0000000..614245c --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tclass.pkg @@ -0,0 +1,97 @@ +$#include "tclass.h" + +$Test::Tst_A* Test::Tst_A::last; +$Test::Tst_B* Test::Tst_B::last; +$Test::Tst_C* Test::Tst_C::last; + + +$renaming ^Tst_ @ + +namespace Test { + +class Tst_Dummy; + +class Tst_A +{ + static Tst_A* last; + Tst_A (); + virtual char* a (); + class Tst_AA + { + Tst_AA () {} + ~Tst_AA () {} + char* aa () { return "AA"; } + }; + class Tst_BB : public Tst_AA + { + Tst_BB () {} + ~Tst_BB () {} + Tst_AA* Base () { return this; } + }; + + tolua_property int number; +}; + +class Tst_E { +public: + typedef enum{ + ONE, + TWO, + } Pete; + Pete pete; + + float get_t<float>(); + + void get_pete(Pete p); + + Tst_E& operator+(const Tst_E& rvalue); + + void pars(int a=0xa, int b=GetNumber(GetNumber(1,2))); + void get_pointer(void* a=NULL); + + void set_ptr(void* p_ptr) { + printf("this is %p, ptr is %p\n", this, p_ptr); + ptr = p_ptr; + }; + void* get_ptr() {return ptr;}; + + Tst_A a; + Tst_E(int); + //~Tst_E(); +}; + + +class Tst_B : public Tst_A +{ + static Tst_B* last; + Tst_B (); + virtual char* b (); + static Tst_A* create(); + static void* create_void() {return new Tst_B;}; +}; + +class Tst_C@luaC : public Tst_B +{ + static Tst_C* last; + Tst_C (int n); + ~Tst_C (); + virtual char* c (); +}; + +Tst_A::Tst_AA* Tst_create_aa (); +bool Tst_is_aa (Tst_A::Tst_AA* obj); + +class Tst_Outside { + + + tolua_outside void outside_func@outside(lua_State* ls); + + static tolua_outside void outside_func@outside_static(Tst_Outside* instance, lua_State* ls); + + Tst_Outside() {}; +}; + + +}; // end of namespace + + diff --git a/ThirdParty/toluapp/src/tests/tconstant.h b/ThirdParty/toluapp/src/tests/tconstant.h new file mode 100644 index 0000000..917ad0a --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tconstant.h @@ -0,0 +1,29 @@ +#define FIRST 1 +#define SECOND 2 + +enum { + ONE = 1, + TWO = 2 +}; + +#define M_FIRST 1 +#define M_SECOND 2 + +enum { + M_ONE = 1, + M_TWO = 2 +}; + +class A { +public: + + #define FIRST 1 + #define SECOND 2 + + enum { + ONE = 1, + TWO = 2 + }; +}; + + diff --git a/ThirdParty/toluapp/src/tests/tconstant.lua b/ThirdParty/toluapp/src/tests/tconstant.lua new file mode 100644 index 0000000..f7753fe --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tconstant.lua @@ -0,0 +1,11 @@ +assert(FIRST==M.FIRST) +assert(FIRST==A.FIRST) +assert(SECOND==M.SECOND) +assert(SECOND==A.SECOND) + +assert(ONE==M.ONE) +assert(ONE==A.ONE) +assert(TWO==M.TWO) +assert(TWO==A.TWO) + +print("Constant test OK") diff --git a/ThirdParty/toluapp/src/tests/tconstant.pkg b/ThirdParty/toluapp/src/tests/tconstant.pkg new file mode 100644 index 0000000..ada3390 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tconstant.pkg @@ -0,0 +1,34 @@ +$#include "tconstant.h" + +#define FIRST 1 +#define SECOND 2 + +enum { + ONE = 1, + TWO = 2 +}; + +module M { + +#define M_FIRST@FIRST 1 +#define M_SECOND@SECOND 2 + +enum { + M_ONE@ONE = 1, + M_TWO@TWO = 2 +}; +} + +class A { +public: + + #define FIRST 1 + #define SECOND 2 + + enum { + ONE = 1, + TWO = 2 + }; +}; + + diff --git a/ThirdParty/toluapp/src/tests/tdirective.lua b/ThirdParty/toluapp/src/tests/tdirective.lua new file mode 100644 index 0000000..547b150 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tdirective.lua @@ -0,0 +1,6 @@ +assert(a==3) +assert(A==4) +assert(func()==5) + +print("Directive test OK") + diff --git a/ThirdParty/toluapp/src/tests/tdirective.pkg b/ThirdParty/toluapp/src/tests/tdirective.pkg new file mode 100644 index 0000000..cc1f84e --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tdirective.pkg @@ -0,0 +1,28 @@ +$#include "lualib.h" +$#include "lauxlib.h" + +$int a; +$extern int a; + +$int main (void) +${ +$ lua_State* L = lua_open(); +$ luaopen_base(L); +$ tolua_tdirective_open(L); +$ lua_dofile(L,"tdirective.lua"); +$ lua_close(L); +$ return 0; +$} + +$pfile "tdirectivepkg.pkg" + +$< + a = 3; +$> + +$[ +A = 4 +$] + +$lfile "tdirectivelua.lua" + diff --git a/ThirdParty/toluapp/src/tests/tdirectivebind.c b/ThirdParty/toluapp/src/tests/tdirectivebind.c new file mode 100644 index 0000000..28c1234 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tdirectivebind.c @@ -0,0 +1,85 @@ +/* +** Lua binding: tdirective +** Generated automatically by tolua 5.0a-CDLVS2 on 08/08/03 17:06:24. +*/ + +#ifndef __cplusplus +#include "stdlib.h" +#endif +#include "string.h" + +#include "tolua.h" + +/* Exported function */ +TOLUA_API int tolua_tdirective_open (lua_State* tolua_S); + +#include "lualib.h" +#include "lauxlib.h" +int a; +extern int a; +int main (void) +{ + lua_State* L = lua_open(); + luaopen_base(L); + tolua_tdirective_open(L); + lua_dofile(L,"tdirective.lua"); + lua_close(L); + return 0; +} + +/* function to register type */ +static void tolua_reg_types (lua_State* tolua_S) +{ +} + +/* get function: a */ +static int tolua_get_a(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)a); + return 1; +} + +/* set function: a */ +static int tolua_set_a(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + a = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* Open function */ +TOLUA_API int tolua_tdirective_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_variable(tolua_S,"a",tolua_get_a,tolua_set_a); +{ + a = 3; +} + + { /* begin embedded lua code */ + static unsigned char B[] = { + 10, 65, 32, 61, 32, 52,32 + }; + lua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code"); + } /* end of embedded lua code */ + + + { /* begin embedded lua code */ + static unsigned char B[] = { + 10,102,117,110, 99,116,105,111,110, 32,102,117,110, 99, 32, + 40, 41, 10,114,101,116,117,114,110, 32, 53, 10,101,110,100, + 32 + }; + lua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code"); + } /* end of embedded lua code */ + + tolua_endmodule(tolua_S); + return 1; +} diff --git a/ThirdParty/toluapp/src/tests/tdirectivelua.lua b/ThirdParty/toluapp/src/tests/tdirectivelua.lua new file mode 100644 index 0000000..f7c7c15 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tdirectivelua.lua @@ -0,0 +1,3 @@ +function func () + return 5 +end diff --git a/ThirdParty/toluapp/src/tests/tdirectivepkg.pkg b/ThirdParty/toluapp/src/tests/tdirectivepkg.pkg new file mode 100644 index 0000000..b15a66e --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tdirectivepkg.pkg @@ -0,0 +1,2 @@ +extern int a; + diff --git a/ThirdParty/toluapp/src/tests/tfunction.h b/ThirdParty/toluapp/src/tests/tfunction.h new file mode 100644 index 0000000..9c69f06 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tfunction.h @@ -0,0 +1,220 @@ +#ifndef tfunction_h +#define tfunction_h + +#include <stdio.h> +#include <string.h> + +typedef enum { + FIRST = 1, + SECOND = 2 +} Order; + +class Point +{ + char m_s[64]; + float m_x; + float m_y; + +public: + + enum Error { + SUCCESS = 0, + ERROR = 1 + }; + + Point (float x=0, float y=0) + : m_x(x), m_y(y) + { + } + virtual ~Point () + { + } + + void set (float x, float y) + { + m_x = x, m_y = y; + } + void set (float v[2]=0) + { + m_x = v[0], m_y=v[1]; + } + void setpointer (Point* p) + { + *this = *p; + } + void setref (Point& p) + { + *this = p; + } + void setvalue (Point p) + { + *this = p; + } + void setconst (const Point* p) + { + *this = *p; + } + void setname (const char* s) + { + strncpy(m_s,s,63); + } + + void get (float* x, float* y) const + { + *x = m_x, *y = m_y; + } + void get (float v[2]) const + { + v[0] = m_x, v[1] = m_y; + } + Point* getpointer () + { + return this; + } + Point& getref () + { + return *this; + } + Point getvalue () + { + return *this; + } + const Point* getconst () const + { + return this; + } + const char* getname () const + { + return m_s; + } + + Point operator+ (const Point& p) const + { + return Point(m_x+p.m_x,m_y+p.m_y); + } + Point operator- (const Point& p) const + { + return Point(m_x-p.m_x,m_y-p.m_y); + } + Point operator* (const Point& p) const + { + return Point(m_x*p.m_x,m_y*p.m_y); + } + Point operator/ (float n) const + { + return Point(m_x/n,m_y/n); + } + bool operator< (const Point& p) const + { + if (m_x < p.m_x) return true; + else if (m_x > p.m_x) return false; + else return m_y < p.m_y; + } + bool operator<= (const Point& p) const + { + return operator<(p) || operator==(p); + } + bool operator== (const Point& p) const + { + return m_x==p.m_x && m_y==p.m_y; + } + + float operator[] (int i) const + { + return (i==0) ? m_x : m_y; + } + float& operator[] (int i) + { + return (i==0) ? m_x : m_y; + } + + static Error echo (Error e) + { + return e; + } + +}; + + +inline Point add (const Point& p1, const Point& p2) +{ + return p1+p2; +} +inline Point sub (const Point& p1, const Point& p2) +{ + return p1-p2; +} +inline Point mult (const Point& p1, const Point& p2) +{ + return p1*p2; +} +inline Point div (const Point& p1, float n) +{ + return p1/n; +} + +inline void getpoint (const Point* p, float* x, float* y) +{ + p->get(x,y); +} +inline void setpoint (Point* p, float x=0, float y=0) +{ + p->set(x,y); +} + +inline Point average (int n, Point v[]) +{ + Point p(0,0); + for (int i=0; i<n; ++i) + p = p+v[i]; + return p/n; +} + +inline Point averagepointer (int n, Point* v[]) +{ + Point p(0,0); + for (int i=0; i<n; ++i) + p = p+(*v[i]); + return p/n; +} + +inline void copyvector (int n, const Point v[], Point u[]) +{ + for (int i=0; i<n; ++i) + u[i] = v[i]; +} + +inline Order invert (Order o) +{ + if (o==FIRST) + return SECOND; + else + return FIRST; +} + + +class ColorPoint : public Point //tolua_export +{ //tolua_export + float r, g, b; +public: + +//tolua_begin + ColorPoint (float px, float py, float cr=0.0f, float cg=0.0f, float cb=0.0f) + : Point(px,py), r(cr), g(cg), b(cb) + { + } + virtual ~ColorPoint () { } + + virtual void getcolor (float* red, float *green, float *blue) const + { + *red = r; + *green = g; + *blue = b; + } + static ColorPoint* MakeRed (float x, float y) + { + return new ColorPoint(x,y,1,0,0); + } +}; +//tolua_end +#endif diff --git a/ThirdParty/toluapp/src/tests/tfunction.lua b/ThirdParty/toluapp/src/tests/tfunction.lua new file mode 100644 index 0000000..61f8d99 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tfunction.lua @@ -0,0 +1,104 @@ +local p = Point:new(1,2) +local q = Point:new() + +local x, y = p:get() +local c = {}; q:get(c) + +assert(x==1 and y==2) +assert(c[1]==0 and c[2]==0) + +q:set(4,5) +q:setname("mypoint") +p:setconst(q) +local r = p:getpointer(); +x,y = r:get() +assert(x==4 and y==5) +assert(r:getname()=="mypoint") + +local s = Point:new() +s:setref(r) +local t = s:getref() +t:set(5,6) -- t is s +x,y = s:get() +assert(x==5 and y==6) + +local u = s:getvalue() +u:set(4,1) -- u represents a copy of s +x,y = s:get() +assert(x~=4 and y~=1) + +local x1,y1 = getpoint(u) +local x2,y2 = getpoint(s) + +local p1 = alg.add(u,s) +x,y = p1:get() +assert(x==x1+x2 and y==y1+y2) + +local p2 = alg.sub(u,s) +x,y = p2:get() +assert(x==x1-x2 and y==y1-y2) + +local p3 = alg.mult(u,s) +x,y = p3:get() +assert(x==x1*x2 and y==y1*y2) + +local p4 = alg.div(s,2) +x,y = p4:get() +assert(x==x2/2 and y==y2/2) + +setpoint(p4) +x,y = p4:get() +assert(x==0 and y==0) + +local cp = ColorPoint:MakeRed(3,4) +local p = cp+cp +x,y = p:get() +assert(x==6 and y==8) +local q = p-cp +x,y = q:get() +assert(x==3 and y==4) +local r = p/2 +x,y = r:get() +assert(x==3 and y==4) +local t = r*cp +x,y = t:get() +assert(x==9 and y==16) +assert(t==r*r) +-- assert(q==cp) -- the eq does not deal with different metatables +assert(t~=q) +assert(q<t) +assert(q<=t) +assert(t>q) +assert(t>=q) + +local p = Point:new(1,2) +assert(p[1]==1 and p[2]==2) +p[1]=3; p[2] = p[2]+2 +local x, y = p:get() +assert(x==3 and y==4) + + +local n = 3 +local v = {Point:new(0,1), Point:new(2,3), Point:new(4,5)} + +local m = average(n,v) +local c = averagepointer(n,v) +local t = {} +copyvector(n,v,t) + +local l = Point:new() +for i=1,n do + assert(v[i]==t[i]) + l[1] = l[1] + v[i][1] + l[2] = l[2] + v[i][2] +end +l = l/n +assert(m==l) +assert(c==l) + +assert(Point.SUCCESS==Point:echo(Point.SUCCESS)) +assert(Point.ERROR==Point:echo(Point.ERROR)) +assert(FIRST==invert(SECOND)) +assert(SECOND==invert(FIRST)) + +print("Function test OK") diff --git a/ThirdParty/toluapp/src/tests/tfunction.pkg b/ThirdParty/toluapp/src/tests/tfunction.pkg new file mode 100644 index 0000000..bae3f43 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tfunction.pkg @@ -0,0 +1,74 @@ +$#include "tfunction.h" + +typedef enum { + FIRST = 1, + SECOND = 2 +} Order; + +class Point +{ + enum Error { + SUCCESS = 0, + ERROR = 1 + }; + + Point (float x=0, float y=0); + virtual ~Point (); + + void set (float x, float y); + void set (float v[2]=0); + void setpointer (Point* p); + void setref (Point& p); + void setvalue (Point p); + void setconst (const Point* p); + void setname (const char* s); + + void get (float* x=0, float* y=0) const; + void get (float v[2]=0) const; + Point* getpointer (); + Point& getref (); + Point getvalue (); + const Point* getconst () const; + const char* getname () const; + + Point operator+ (const Point& p) const; + Point operator- (const Point& p) const; + Point operator* (const Point& p) const; + Point operator/ (float n) const; + bool operator< (const Point& p) const; + bool operator<= (const Point& p) const; + bool operator== (const Point& p) const; + + float operator[] (int i) const; + float& operator[] (int i); + + static Error echo (Error e); +}; + +module alg +{ + Point add (const Point& p1, const Point& p2); + Point sub (const Point& p1, const Point& p2); + Point mult (const Point& p1, const Point& p2); + Point div (const Point& p1, float n); +} + +void getpoint (const Point* p, float* x=0, float* y=0); +void setpoint (Point* p, float x=0, float y=0); +inline Point average (int n, Point v[n]); +inline Point averagepointer (int n, Point* v[n]); +inline void copyvector (int n, const Point v[n], Point u[n]=(u+i)); + +inline Order invert (Order o); + +$cfile "tfunction.h" + +/* +class ColorPoint : public Point +{ + ColorPoint (float px, float py, float cr=0.0f, float cg=0.0f, float cb=0.0f); + virtual ~ColorPoint (); + virtual void getcolor (float* red, float *green, float *blue) const; + static const Point* MakeRed (float x, float y); +}; +*/ diff --git a/ThirdParty/toluapp/src/tests/tmodule.c b/ThirdParty/toluapp/src/tests/tmodule.c new file mode 100644 index 0000000..1cbfa29 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tmodule.c @@ -0,0 +1,24 @@ +#include "lualib.h" +#include "lauxlib.h" + +#include "tmodule.h" + +int a = 1; +int b = 2; +int c = 3; +int d = 4; + +int main () +{ + int tolua_tmodule_open (lua_State*); + + lua_State* L = lua_open(); + luaopen_base(L); + tolua_tmodule_open(L); + + lua_dofile(L,"tmodule.lua"); + + lua_close(L); + return 0; +} + diff --git a/ThirdParty/toluapp/src/tests/tmodule.h b/ThirdParty/toluapp/src/tests/tmodule.h new file mode 100644 index 0000000..3766bc4 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tmodule.h @@ -0,0 +1,7 @@ +#include <stdio.h> + +extern int a; +extern int b; +extern int c; +extern int d; + diff --git a/ThirdParty/toluapp/src/tests/tmodule.lua b/ThirdParty/toluapp/src/tests/tmodule.lua new file mode 100644 index 0000000..96ddf43 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tmodule.lua @@ -0,0 +1,17 @@ +-- test valid access +assert(A.a==1) +assert(A.B.b==2) +assert(A.B.C.c==3) + +-- test invalid access +assert(A.B.a==nil) -- no inheritance +assert(A.B.C.a==nil) + +assert(A.b==nil) -- no access the inner module +assert(A.c==nil) +assert(A.B.c==nil) + +-- test variables appended to existing modules +assert(A.d==4) + +print("Module test OK") diff --git a/ThirdParty/toluapp/src/tests/tmodule.pkg b/ThirdParty/toluapp/src/tests/tmodule.pkg new file mode 100644 index 0000000..43d4306 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tmodule.pkg @@ -0,0 +1,16 @@ + +$#include "tmodule.h" + +module A { + extern int a; + module B { + extern int b; + module C { + extern int c; + } + } +} + +module A { + extern int d; +} diff --git a/ThirdParty/toluapp/src/tests/tmodulebind.c b/ThirdParty/toluapp/src/tests/tmodulebind.c new file mode 100644 index 0000000..0175a46 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tmodulebind.c @@ -0,0 +1,124 @@ +/* +** Lua binding: tmodule +** Generated automatically by tolua 5.0a-CDLVS2 on 08/08/03 17:06:13. +*/ + +#ifndef __cplusplus +#include "stdlib.h" +#endif +#include "string.h" + +#include "tolua.h" + +/* Exported function */ +TOLUA_API int tolua_tmodule_open (lua_State* tolua_S); + +#include "tmodule.h" + +/* function to register type */ +static void tolua_reg_types (lua_State* tolua_S) +{ +} + +/* get function: a */ +static int tolua_get_A_a(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)a); + return 1; +} + +/* set function: a */ +static int tolua_set_A_a(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + a = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: b */ +static int tolua_get_B_b(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)b); + return 1; +} + +/* set function: b */ +static int tolua_set_B_b(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + b = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: c */ +static int tolua_get_C_c(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)c); + return 1; +} + +/* set function: c */ +static int tolua_set_C_c(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + c = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: d */ +static int tolua_get_A_d(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)d); + return 1; +} + +/* set function: d */ +static int tolua_set_A_d(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + d = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* Open function */ +TOLUA_API int tolua_tmodule_open (lua_State* tolua_S) +{ + tolua_open(tolua_S); + tolua_reg_types(tolua_S); + tolua_module(tolua_S,NULL,0); + tolua_beginmodule(tolua_S,NULL); + tolua_module(tolua_S,"A",1); + tolua_beginmodule(tolua_S,"A"); + tolua_variable(tolua_S,"a",tolua_get_A_a,tolua_set_A_a); + tolua_module(tolua_S,"B",1); + tolua_beginmodule(tolua_S,"B"); + tolua_variable(tolua_S,"b",tolua_get_B_b,tolua_set_B_b); + tolua_module(tolua_S,"C",1); + tolua_beginmodule(tolua_S,"C"); + tolua_variable(tolua_S,"c",tolua_get_C_c,tolua_set_C_c); + tolua_endmodule(tolua_S); + tolua_endmodule(tolua_S); + tolua_endmodule(tolua_S); + tolua_module(tolua_S,"A",1); + tolua_beginmodule(tolua_S,"A"); + tolua_variable(tolua_S,"d",tolua_get_A_d,tolua_set_A_d); + tolua_endmodule(tolua_S); + tolua_endmodule(tolua_S); + return 1; +} diff --git a/ThirdParty/toluapp/src/tests/tnamespace.h b/ThirdParty/toluapp/src/tests/tnamespace.h new file mode 100644 index 0000000..8c15e41 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tnamespace.h @@ -0,0 +1,11 @@ +namespace A { + enum {FIRST=1}; + extern int a; + namespace B { + extern int b; + namespace C { + extern int c; + } + } +} + diff --git a/ThirdParty/toluapp/src/tests/tnamespace.lua b/ThirdParty/toluapp/src/tests/tnamespace.lua new file mode 100644 index 0000000..3a51dfb --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tnamespace.lua @@ -0,0 +1,14 @@ +-- test valid access +assert(A.a==1) +assert(A.B.b==2) +assert(A.B.C.c==3) + +-- test invalid access +assert(A.B.a==nil) -- no inheritance +assert(A.B.C.a==nil) + +assert(A.b==nil) -- no access the inner module +assert(A.c==nil) +assert(A.B.c==nil) + +print("Namespace test OK") diff --git a/ThirdParty/toluapp/src/tests/tnamespace.pkg b/ThirdParty/toluapp/src/tests/tnamespace.pkg new file mode 100644 index 0000000..0b58366 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tnamespace.pkg @@ -0,0 +1,13 @@ + +$#include "tnamespace.h" + +namespace A { + int a; + namespace B { + int b; + namespace C { + int c; + } + } +} + diff --git a/ThirdParty/toluapp/src/tests/tvariable.c b/ThirdParty/toluapp/src/tests/tvariable.c new file mode 100644 index 0000000..25e788e --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tvariable.c @@ -0,0 +1,46 @@ +#include "lualib.h" +#include "lauxlib.h" + +#include "tvariable.h" + +int i = 1; +float f = 2.0f;; +double d = 3.0; +char* s = "Hello world"; +void* v = (void*)1; +char n[64] = "Hi there"; + +A a = {11,12.0f,13.0,"Hello world from class",(void*)1,"Hi there from class"}; +B* b; +U u; + +int mi = 21; +float mf = 22.0f; +double md = 23.0; +char* ms = "Hello world in module"; +void* mv = NULL; +char mn[64] = "Hi there in module"; +A ma = {31,32.0f,33.0,"Hello world from class in module", + NULL,"Hi there from class in module"}; +B* mb; + +int main (void) +{ + int tolua_tvariable_open (lua_State*); + lua_State* L = lua_open(); + + B bb = {a,NULL}; + B bbb = {ma,&bb}; + b = &bb; + mb = &bbb; + + + luaopen_base(L); + tolua_tvariable_open(L); + + lua_dofile(L,"tvariable.lua"); + + lua_close(L); + return 0; +} + diff --git a/ThirdParty/toluapp/src/tests/tvariable.h b/ThirdParty/toluapp/src/tests/tvariable.h new file mode 100644 index 0000000..6363c48 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tvariable.h @@ -0,0 +1,44 @@ +typedef struct A A; +typedef struct B B; +typedef union U U; + +struct A +{ + int i; + float f; + double d; + char* s; + void* v; + char n[64]; +}; + +union U +{ + int i; + float f; +}; + +struct B +{ + A a; + B* b; +}; + +extern int i; +extern float f; +extern double d; +extern char* s; +extern void* v; +extern char n[64]; +extern A a; +extern B* b; +extern U u; + +extern int mi; +extern float mf; +extern double md; +extern char* ms; +extern void* mv; +extern char mn[64]; +extern A ma; +extern B* mb; diff --git a/ThirdParty/toluapp/src/tests/tvariable.lua b/ThirdParty/toluapp/src/tests/tvariable.lua new file mode 100644 index 0000000..3db9029 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tvariable.lua @@ -0,0 +1,73 @@ +assert(i==1) +assert(f==2) +assert(d==3) +assert(s=="Hello world") +assert(n=="Hi there") +n = "Hello" +assert(n=="Hello") + +assert(a.i==11) +assert(a.f==12) +assert(a.d==13) +assert(a.s=="Hello world from class") +assert(a.n=="Hi there from class") +a.n = "Hello from class" +assert(a.n=="Hello from class") + +assert(v==a.v) + +u.i = 2 +assert(u.i==2) +u.f = 2 +assert(u.f==2) +assert(u.i~=2) + +assert(M.mi==21) +assert(M.mf==22) +assert(M.md==23) +assert(M.ms=="Hello world in module") +assert(M.mn=="Hi there in module") +M.mn = "Hello in module" +assert(M.mn=="Hello in module") +assert(M.mv==nil) + +assert(M.ma.i==31) +assert(M.ma.f==32) +assert(M.ma.d==33) +assert(M.ma.s=="Hello world from class in module") +assert(M.ma.n=="Hi there from class in module") +M.ma.n = "Hello from class in module" +assert(M.ma.n=="Hello from class in module") +assert(M.ma.v==nil) + +assert(a.i==b.a.i) +assert(a.f==b.a.f) +assert(a.d==b.a.d) +assert(a.s==b.a.s) +assert(a.v==b.a.v) +assert(b.b==nil) + +assert(M.ma.i==M.mb.a.i) +assert(M.ma.f==M.mb.a.f) +assert(M.ma.d==M.mb.a.d) +assert(M.ma.s==M.mb.a.s) +assert(M.ma.v==M.mb.a.v) + +assert(a.i==M.mb.b.a.i) +assert(a.f==M.mb.b.a.f) +assert(a.d==M.mb.b.a.d) +assert(a.s==M.mb.b.a.s) +assert(a.v==M.mb.b.a.v) +assert(M.mb.b.b==nil) + +assert(s~=rawget(_G,"s")) -- because s represents a C variable +s = "Hello" +assert(s==rawget(_G,"s")) -- because s is mapped as const + +f = 25.0 +assert(f~=rawget(_G,"f")) -- because f represents a C variable + +b.a.i = 5 +assert(b.a.i==M.mb.b.a.i) + +print("Variable test OK") diff --git a/ThirdParty/toluapp/src/tests/tvariable.pkg b/ThirdParty/toluapp/src/tests/tvariable.pkg new file mode 100644 index 0000000..a8a1539 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tvariable.pkg @@ -0,0 +1,45 @@ +$#include "tvariable.h" + +struct A +{ + int i; + float f; + double d; + char* s; + void* v; + char n[64]; +}; + +struct B +{ + A a; + B* b; +}; + +union U +{ + int i; + float f; +}; + +extern int i; +extern float f; +extern double d; +extern const char* s; +extern void* v; +extern char n[64]; +extern A a; +extern B* b; +extern U u; + +module M { +extern int mi; +extern float mf; +extern double md; +extern const char* ms; +extern void* mv; +extern const char mn[64]; +extern A a; +extern A ma; +extern B* mb; +} diff --git a/ThirdParty/toluapp/src/tests/tvariablebind.c b/ThirdParty/toluapp/src/tests/tvariablebind.c new file mode 100644 index 0000000..9a50e36 --- /dev/null +++ b/ThirdParty/toluapp/src/tests/tvariablebind.c @@ -0,0 +1,631 @@ +/* +** Lua binding: tvariable +** Generated automatically by tolua 5.0a-CDLVS2 on 08/08/03 17:06:18. +*/ + +#ifndef __cplusplus +#include "stdlib.h" +#endif +#include "string.h" + +#include "tolua.h" + +/* Exported function */ +TOLUA_API int tolua_tvariable_open (lua_State* tolua_S); + +#include "tvariable.h" + +/* function to register type */ +static void tolua_reg_types (lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"A"); + tolua_usertype(tolua_S,"U"); + tolua_usertype(tolua_S,"B"); +} + +/* get function: i of class A */ +static int tolua_get_A_i(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'i'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->i); + return 1; +} + +/* set function: i of class A */ +static int tolua_set_A_i(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'i'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->i = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: f of class A */ +static int tolua_get_A_f(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'f'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->f); + return 1; +} + +/* set function: f of class A */ +static int tolua_set_A_f(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'f'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->f = ((float) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: d of class A */ +static int tolua_get_A_d(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'd'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->d); + return 1; +} + +/* set function: d of class A */ +static int tolua_set_A_d(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'd'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->d = ((double) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: s of class A */ +static int tolua_get_A_s(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 's'",NULL); +#endif + tolua_pushstring(tolua_S,(const char*)self->s); + return 1; +} + +/* set function: s of class A */ +static int tolua_set_A_s(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 's'",NULL); + if (!tolua_isstring(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->s = ((char*) tolua_tostring(tolua_S,2,0)); + return 0; +} + +/* get function: v of class A */ +static int tolua_get_A_v(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'v'",NULL); +#endif + tolua_pushuserdata(tolua_S,(void*)self->v); + return 1; +} + +/* set function: v of class A */ +static int tolua_set_A_v(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'v'",NULL); + if (!tolua_isuserdata(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->v = ((void*) tolua_touserdata(tolua_S,2,0)); + return 0; +} + +/* get function: n of class A */ +static int tolua_get_A_n(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'n'",NULL); +#endif + tolua_pushstring(tolua_S,(const char*)self->n); + return 1; +} + +/* set function: n of class A */ +static int tolua_set_A_n(lua_State* tolua_S) +{ + A* self = (A*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'n'",NULL); + if (!tolua_isstring(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + strncpy(self->n,tolua_tostring(tolua_S,2,0),64-1); + return 0; +} + +/* get function: a of class B */ +static int tolua_get_B_a(lua_State* tolua_S) +{ + B* self = (B*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'a'",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)&self->a,"A"); + return 1; +} + +/* set function: a of class B */ +static int tolua_set_B_a(lua_State* tolua_S) +{ + B* self = (B*) 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_isusertype(tolua_S,2,"A",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->a = *((A*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: b of class B */ +static int tolua_get_B_b_ptr(lua_State* tolua_S) +{ + B* self = (B*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'b'",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)self->b,"B"); + return 1; +} + +/* set function: b of class B */ +static int tolua_set_B_b_ptr(lua_State* tolua_S) +{ + B* self = (B*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'b'",NULL); + if (!tolua_isusertype(tolua_S,2,"B",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->b = ((B*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: i of class U */ +static int tolua_get_U_i(lua_State* tolua_S) +{ + U* self = (U*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'i'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->i); + return 1; +} + +/* set function: i of class U */ +static int tolua_set_U_i(lua_State* tolua_S) +{ + U* self = (U*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'i'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->i = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: f of class U */ +static int tolua_get_U_f(lua_State* tolua_S) +{ + U* self = (U*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'f'",NULL); +#endif + tolua_pushnumber(tolua_S,(double)self->f); + return 1; +} + +/* set function: f of class U */ +static int tolua_set_U_f(lua_State* tolua_S) +{ + U* self = (U*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'f'",NULL); + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->f = ((float) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: i */ +static int tolua_get_i(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)i); + return 1; +} + +/* set function: i */ +static int tolua_set_i(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + i = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: f */ +static int tolua_get_f(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)f); + return 1; +} + +/* set function: f */ +static int tolua_set_f(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + f = ((float) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: d */ +static int tolua_get_d(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)d); + return 1; +} + +/* set function: d */ +static int tolua_set_d(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + d = ((double) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: s */ +static int tolua_get_s(lua_State* tolua_S) +{ + tolua_pushstring(tolua_S,(const char*)s); + return 1; +} + +/* get function: v */ +static int tolua_get_v(lua_State* tolua_S) +{ + tolua_pushuserdata(tolua_S,(void*)v); + return 1; +} + +/* set function: v */ +static int tolua_set_v(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isuserdata(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + v = ((void*) tolua_touserdata(tolua_S,2,0)); + return 0; +} + +/* get function: n */ +static int tolua_get_n(lua_State* tolua_S) +{ + tolua_pushstring(tolua_S,(const char*)n); + return 1; +} + +/* set function: n */ +static int tolua_set_n(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isstring(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + strncpy(n,tolua_tostring(tolua_S,2,0),64-1); + return 0; +} + +/* get function: a */ +static int tolua_get_a(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)&a,"A"); + return 1; +} + +/* set function: a */ +static int tolua_set_a(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"A",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + a = *((A*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: b */ +static int tolua_get_b_ptr(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)b,"B"); + return 1; +} + +/* set function: b */ +static int tolua_set_b_ptr(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"B",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + b = ((B*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: u */ +static int tolua_get_u(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)&u,"U"); + return 1; +} + +/* set function: u */ +static int tolua_set_u(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"U",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + u = *((U*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: mi */ +static int tolua_get_M_mi(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)mi); + return 1; +} + +/* set function: mi */ +static int tolua_set_M_mi(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + mi = ((int) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: mf */ +static int tolua_get_M_mf(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)mf); + return 1; +} + +/* set function: mf */ +static int tolua_set_M_mf(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + mf = ((float) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: md */ +static int tolua_get_M_md(lua_State* tolua_S) +{ + tolua_pushnumber(tolua_S,(double)md); + return 1; +} + +/* set function: md */ +static int tolua_set_M_md(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + md = ((double) tolua_tonumber(tolua_S,2,0)); + return 0; +} + +/* get function: ms */ +static int tolua_get_M_ms(lua_State* tolua_S) +{ + tolua_pushstring(tolua_S,(const char*)ms); + return 1; +} + +/* get function: mv */ +static int tolua_get_M_mv(lua_State* tolua_S) +{ + tolua_pushuserdata(tolua_S,(void*)mv); + return 1; +} + +/* set function: mv */ +static int tolua_set_M_mv(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isuserdata(tolua_S,2,0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + mv = ((void*) tolua_touserdata(tolua_S,2,0)); + return 0; +} + +/* get function: mn */ +static int tolua_get_M_mn(lua_State* tolua_S) +{ + tolua_pushstring(tolua_S,(const char*)mn); + return 1; +} + +/* get function: a */ +static int tolua_get_M_a(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)&a,"A"); + return 1; +} + +/* set function: a */ +static int tolua_set_M_a(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"A",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + a = *((A*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: ma */ +static int tolua_get_M_ma(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)&ma,"A"); + return 1; +} + +/* set function: ma */ +static int tolua_set_M_ma(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"A",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + ma = *((A*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* get function: mb */ +static int tolua_get_M_mb_ptr(lua_State* tolua_S) +{ + tolua_pushusertype(tolua_S,(void*)mb,"B"); + return 1; +} + +/* set function: mb */ +static int tolua_set_M_mb_ptr(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,2,"B",0,&tolua_err)) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + mb = ((B*) tolua_tousertype(tolua_S,2,0)); + return 0; +} + +/* Open function */ +TOLUA_API int tolua_tvariable_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,"A","A","",NULL); + tolua_beginmodule(tolua_S,"A"); + tolua_variable(tolua_S,"i",tolua_get_A_i,tolua_set_A_i); + tolua_variable(tolua_S,"f",tolua_get_A_f,tolua_set_A_f); + tolua_variable(tolua_S,"d",tolua_get_A_d,tolua_set_A_d); + tolua_variable(tolua_S,"s",tolua_get_A_s,tolua_set_A_s); + tolua_variable(tolua_S,"v",tolua_get_A_v,tolua_set_A_v); + tolua_variable(tolua_S,"n",tolua_get_A_n,tolua_set_A_n); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"B","B","",NULL); + tolua_beginmodule(tolua_S,"B"); + tolua_variable(tolua_S,"a",tolua_get_B_a,tolua_set_B_a); + tolua_variable(tolua_S,"b",tolua_get_B_b_ptr,tolua_set_B_b_ptr); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"U","U","",NULL); + tolua_beginmodule(tolua_S,"U"); + tolua_variable(tolua_S,"i",tolua_get_U_i,tolua_set_U_i); + tolua_variable(tolua_S,"f",tolua_get_U_f,tolua_set_U_f); + tolua_endmodule(tolua_S); + tolua_variable(tolua_S,"i",tolua_get_i,tolua_set_i); + tolua_variable(tolua_S,"f",tolua_get_f,tolua_set_f); + tolua_variable(tolua_S,"d",tolua_get_d,tolua_set_d); + tolua_variable(tolua_S,"s",tolua_get_s,NULL); + tolua_variable(tolua_S,"v",tolua_get_v,tolua_set_v); + tolua_variable(tolua_S,"n",tolua_get_n,tolua_set_n); + tolua_variable(tolua_S,"a",tolua_get_a,tolua_set_a); + tolua_variable(tolua_S,"b",tolua_get_b_ptr,tolua_set_b_ptr); + tolua_variable(tolua_S,"u",tolua_get_u,tolua_set_u); + tolua_module(tolua_S,"M",1); + tolua_beginmodule(tolua_S,"M"); + tolua_variable(tolua_S,"mi",tolua_get_M_mi,tolua_set_M_mi); + tolua_variable(tolua_S,"mf",tolua_get_M_mf,tolua_set_M_mf); + tolua_variable(tolua_S,"md",tolua_get_M_md,tolua_set_M_md); + tolua_variable(tolua_S,"ms",tolua_get_M_ms,NULL); + tolua_variable(tolua_S,"mv",tolua_get_M_mv,tolua_set_M_mv); + tolua_variable(tolua_S,"mn",tolua_get_M_mn,NULL); + tolua_variable(tolua_S,"a",tolua_get_M_a,tolua_set_M_a); + tolua_variable(tolua_S,"ma",tolua_get_M_ma,tolua_set_M_ma); + tolua_variable(tolua_S,"mb",tolua_get_M_mb_ptr,tolua_set_M_mb_ptr); + tolua_endmodule(tolua_S); + tolua_endmodule(tolua_S); + return 1; +} |