diff options
author | Determinant <[email protected]> | 2015-05-14 15:01:55 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-05-14 15:01:55 +0800 |
commit | f48dc493b5b77fd4e4472dd6c78b7542a4884129 (patch) | |
tree | 0b7a0f95df28fc100fc1fd252ce1d0215d19150d /oop_example.c | |
parent | 46ccec6d5ad057476e945afa34981f7e8d732547 (diff) |
add basic matrix implementation
Diffstat (limited to 'oop_example.c')
-rw-r--r-- | oop_example.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/oop_example.c b/oop_example.c index fecac14..e9a4ffe 100644 --- a/oop_example.c +++ b/oop_example.c @@ -6,32 +6,34 @@ #include <stdio.h> #include <stdlib.h> +const char *point_tname = "nerv.Point"; + typedef struct { double x, y; int arr[100]; } Point; static int point_get_sinx (lua_State *L) { - Point *p = luaT_checkudata(L, 1, "nerv.point"); + Point *p = luaT_checkudata(L, 1, point_tname); lua_pushnumber(L, sin(p->x)); return 1; } static int point_set_x (lua_State *L) { - Point *p = luaT_checkudata(L, 1, "nerv.point"); + Point *p = luaT_checkudata(L, 1, point_tname); p->x = luaL_checknumber(L, 2); return 0; } static int point_get_y(lua_State *L) { - Point *p = luaT_checkudata(L, 1, "nerv.point"); + Point *p = luaT_checkudata(L, 1, point_tname); lua_pushnumber(L, sin(p->x)); return 1; } static int point_newindex(lua_State *L) { - Point *p = luaT_checkudata(L, 1, "nerv.point"); + Point *p = luaT_checkudata(L, 1, point_tname); if (lua_isnumber(L, 2)) { int d = luaL_checkinteger(L, 2); @@ -49,7 +51,7 @@ static int point_newindex(lua_State *L) { } static int point_index(lua_State *L) { - Point *p = luaT_checkudata(L, 1, "nerv.point"); + Point *p = luaT_checkudata(L, 1, point_tname); if (lua_isnumber(L, 2)) { int d = luaL_checkinteger(L, 2); @@ -69,7 +71,7 @@ int point_new(lua_State *L) { Point *self = (Point *)malloc(sizeof(Point)); self->x = 0; self->y = 0; - luaT_pushudata(L, self, "nerv.point"); + luaT_pushudata(L, self, point_tname); return 1; } @@ -83,7 +85,7 @@ static const luaL_Reg point[] = { }; void nerv_point_init(lua_State *L) { - luaT_newmetatable(L, "nerv.point", NULL, point_new, NULL, NULL); + luaT_newmetatable(L, "nerv.Point", NULL, point_new, NULL, NULL); luaL_register(L, NULL, point); lua_pop(L, 1); } |