[395] | 1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
[176] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[176] | 6 |
|
---|
| 7 | #include "nv/lua/lua_area.hh"
|
---|
| 8 |
|
---|
| 9 | #include "nv/lua/lua_raw.hh"
|
---|
[319] | 10 | #include "nv/core/random.hh"
|
---|
[176] | 11 |
|
---|
[207] | 12 | using nv::lua::detail::is_coord;
|
---|
| 13 | using nv::lua::detail::to_coord;
|
---|
| 14 | using nv::lua::detail::to_pcoord;
|
---|
| 15 | using nv::lua::detail::push_coord;
|
---|
[176] | 16 |
|
---|
[207] | 17 | using nv::lua::detail::is_area;
|
---|
| 18 | using nv::lua::detail::to_area;
|
---|
| 19 | using nv::lua::detail::to_parea;
|
---|
| 20 | using nv::lua::detail::push_area;
|
---|
[176] | 21 |
|
---|
[198] | 22 | static void nlua_area_construct( lua_State* L, int sidx )
|
---|
[176] | 23 | {
|
---|
[207] | 24 | if ( is_coord( L, sidx ) )
|
---|
[176] | 25 | {
|
---|
[207] | 26 | if ( is_coord( L, sidx+1 ) )
|
---|
[176] | 27 | {
|
---|
[207] | 28 | nv::rectangle a( to_coord( L, sidx ), to_coord( L, sidx+1 ) );
|
---|
| 29 | push_area( L, a );
|
---|
[176] | 30 | return;
|
---|
| 31 | }
|
---|
| 32 | // TODO: coord, width, height
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | nv::rectangle a(
|
---|
| 36 | nv::ivec2( lua_tointeger( L, sidx ), lua_tointeger( L, sidx+1 ) ),
|
---|
| 37 | nv::ivec2( lua_tointeger( L, sidx+2 ), lua_tointeger( L, sidx+3 ) )
|
---|
| 38 | );
|
---|
[207] | 39 | push_area( L, a );
|
---|
[176] | 40 | }
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | static int nlua_area_new( lua_State* L )
|
---|
| 44 | {
|
---|
| 45 | nlua_area_construct( L, 1 );
|
---|
| 46 | return 1;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | static int nlua_area_call( lua_State* L )
|
---|
| 50 | {
|
---|
| 51 | nlua_area_construct( L, 2 );
|
---|
| 52 | return 1;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | static int nlua_area_eq( lua_State* L )
|
---|
| 56 | {
|
---|
[207] | 57 | lua_pushboolean( L, to_area( L, 1 ) == to_area( L, 2 ) );
|
---|
[176] | 58 | return 1;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | static int nlua_area_get( lua_State* L )
|
---|
| 62 | {
|
---|
[207] | 63 | nv::rectangle r( to_area( L, 1 ) );
|
---|
| 64 | push_coord( L, r.ul );
|
---|
| 65 | push_coord( L, r.lr );
|
---|
[176] | 66 | return 2;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | static int nlua_area_clone( lua_State* L )
|
---|
| 70 | {
|
---|
[207] | 71 | push_area( L, *to_parea( L, 1 ) );
|
---|
[176] | 72 | return 1;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | static int nlua_area_index( lua_State* L )
|
---|
| 76 | {
|
---|
[207] | 77 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[374] | 78 | nv::size_t l;
|
---|
[176] | 79 | const char* index = lua_tolstring( L, 2, &l );
|
---|
| 80 | if ( l == 1 && index[0] == 'a' )
|
---|
| 81 | {
|
---|
[207] | 82 | push_coord( L, a->ul );
|
---|
[176] | 83 | }
|
---|
| 84 | else if ( l == 1 && index[0] == 'b' )
|
---|
| 85 | {
|
---|
[207] | 86 | push_coord( L, a->lr );
|
---|
[176] | 87 | }
|
---|
| 88 | else
|
---|
| 89 | {
|
---|
[179] | 90 | luaL_getmetafield( L, 1, "__functions" );
|
---|
[176] | 91 | lua_pushvalue( L, 2 );
|
---|
| 92 | lua_rawget( L, -2 );
|
---|
| 93 | }
|
---|
| 94 | return 1;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | static int nlua_area_newindex( lua_State* L )
|
---|
| 98 | {
|
---|
[207] | 99 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[374] | 100 | nv::size_t l;
|
---|
[176] | 101 | const char* index = lua_tolstring( L, 2, &l );
|
---|
[207] | 102 | nv::ivec2 value( to_coord( L, 3 ) );
|
---|
[176] | 103 | if ( l == 1 && index[0] == 'a' )
|
---|
| 104 | {
|
---|
| 105 | a->ul = value;
|
---|
| 106 | }
|
---|
| 107 | else if ( l == 1 && index[0] == 'b' )
|
---|
| 108 | {
|
---|
| 109 | a->lr = value;
|
---|
| 110 | }
|
---|
| 111 | return 0;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | static int lua_area_coords_closure( lua_State* L )
|
---|
| 115 | {
|
---|
[207] | 116 | nv::rectangle* a( to_parea( L, lua_upvalueindex(1) ) );
|
---|
| 117 | nv::ivec2* c( to_pcoord( L, lua_upvalueindex(2) ) );
|
---|
[176] | 118 |
|
---|
| 119 | c->x++;
|
---|
| 120 |
|
---|
| 121 | if ( c->x > a->lr.x )
|
---|
| 122 | {
|
---|
| 123 | c->x = a->ul.x;
|
---|
| 124 | c->y++;
|
---|
| 125 | if (c->y > a->lr.y)
|
---|
| 126 | {
|
---|
| 127 | lua_pushnil( L );
|
---|
| 128 | return 1;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[207] | 132 | push_coord( L, *c );
|
---|
[176] | 133 | return 1;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | static int nlua_area_coords( lua_State* L )
|
---|
| 137 | {
|
---|
[207] | 138 | nv::rectangle* a( to_parea( L, 1 ) );
|
---|
[176] | 139 | nv::ivec2 c( a->ul );
|
---|
| 140 | c.x--;
|
---|
[207] | 141 | push_coord( L, c );
|
---|
[176] | 142 | lua_pushcclosure( L, lua_area_coords_closure, 2 );
|
---|
| 143 | return 1;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | static int nlua_area_edges_closure( lua_State* L )
|
---|
| 147 | {
|
---|
[207] | 148 | nv::rectangle* a( to_parea( L, lua_upvalueindex(1) ) );
|
---|
| 149 | nv::ivec2* c( to_pcoord( L, lua_upvalueindex(2) ) );
|
---|
[176] | 150 |
|
---|
| 151 | c->x++;
|
---|
| 152 |
|
---|
| 153 | if ( c->x > a->lr.x )
|
---|
| 154 | {
|
---|
| 155 | c->x = a->ul.x;
|
---|
| 156 | c->y++;
|
---|
| 157 | if (c->y > a->lr.y)
|
---|
| 158 | {
|
---|
| 159 | lua_pushnil( L );
|
---|
| 160 | return 1;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | if (c->y != a->ul.y && c->y != a->lr.y && c->x == a->ul.x + 1 ) c->x = a->ul.x;
|
---|
| 164 |
|
---|
| 165 |
|
---|
[207] | 166 | push_coord( L, *c );
|
---|
[176] | 167 | return 1;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | static int nlua_area_edges( lua_State* L )
|
---|
| 171 | {
|
---|
[207] | 172 | nv::rectangle* a( to_parea( L, 1 ) );
|
---|
[176] | 173 | nv::ivec2 c( a->ul );
|
---|
| 174 | c.x--;
|
---|
[207] | 175 | push_coord( L, c );
|
---|
[176] | 176 | lua_pushcclosure( L, nlua_area_edges_closure, 2 );
|
---|
| 177 | return 1;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | static int nlua_area_corners_closure( lua_State* L )
|
---|
| 181 | {
|
---|
[204] | 182 | int index = static_cast< int >( lua_tointeger( L, lua_upvalueindex(2) ) + 1 );
|
---|
[176] | 183 | lua_pushinteger( L, index );
|
---|
| 184 | lua_replace( L, lua_upvalueindex(2) ); // update
|
---|
| 185 | lua_rawgeti( L, lua_upvalueindex(1), index ); // get value
|
---|
| 186 | return 1;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | static int nlua_area_corners( lua_State* L )
|
---|
| 190 | {
|
---|
[207] | 191 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[176] | 192 |
|
---|
| 193 | lua_createtable(L, 4, 0);
|
---|
[207] | 194 | push_coord( L, a->ul );
|
---|
[176] | 195 | lua_rawseti( L, -2, 1 );
|
---|
[207] | 196 | push_coord( L, a->ur() );
|
---|
[176] | 197 | lua_rawseti( L, -2, 2 );
|
---|
[207] | 198 | push_coord( L, a->ll() );
|
---|
[176] | 199 | lua_rawseti( L, -2, 3 );
|
---|
[207] | 200 | push_coord( L, a->lr );
|
---|
[176] | 201 | lua_rawseti( L, -2, 4 );
|
---|
| 202 |
|
---|
| 203 | lua_pushinteger(L, 0);
|
---|
| 204 | lua_pushcclosure( L, nlua_area_corners_closure, 2 );
|
---|
| 205 | return 1;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | static int nlua_area_shrink( lua_State* L )
|
---|
| 209 | {
|
---|
[207] | 210 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[204] | 211 | a->shrink( static_cast< int >( lua_tointeger( L, 2 ) ) );
|
---|
[176] | 212 | return 0;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | static int nlua_area_shrinked( lua_State* L )
|
---|
| 216 | {
|
---|
[207] | 217 | nv::rectangle* a = to_parea( L, 1 );
|
---|
| 218 | push_area( L, a->shrinked( static_cast< int >( lua_tointeger( L, 2 ) ) ) );
|
---|
[176] | 219 | return 1;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | static int nlua_area_expand( lua_State* L )
|
---|
| 223 | {
|
---|
[207] | 224 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[204] | 225 | a->expand( static_cast< int >( lua_tointeger( L, 2 ) ) );
|
---|
[176] | 226 | return 0;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | static int nlua_area_expanded( lua_State* L )
|
---|
| 230 | {
|
---|
[207] | 231 | nv::rectangle* a = to_parea( L, 1 );
|
---|
| 232 | push_area( L, a->expanded( static_cast< int >( lua_tointeger( L, 2 ) ) ) );
|
---|
[176] | 233 | return 1;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | static int nlua_area_clamp( lua_State* L )
|
---|
| 237 | {
|
---|
[207] | 238 | nv::rectangle* a1 = to_parea( L, 1 );
|
---|
| 239 | nv::rectangle* a2 = to_parea( L, 2 );
|
---|
[176] | 240 | a1->clamp_to( *a2 );
|
---|
| 241 | return 0;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | static int nlua_area_clamped( lua_State* L )
|
---|
| 245 | {
|
---|
[207] | 246 | nv::rectangle a1 = to_area( L, 1 );
|
---|
| 247 | nv::rectangle* a2 = to_parea( L, 2 );
|
---|
[176] | 248 | a1.clamp_to( *a2 );
|
---|
[207] | 249 | push_area( L, a1 );
|
---|
[176] | 250 | return 1;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | static int nlua_area_clamp_coord( lua_State* L )
|
---|
| 254 | {
|
---|
[207] | 255 | nv::rectangle* a = to_parea( L, 1 );
|
---|
| 256 | nv::ivec2* c = to_pcoord( L, 2 );
|
---|
[454] | 257 | *c = nv::math::clamp( *c, a->ul, a->lr );
|
---|
[176] | 258 | return 0;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | static int nlua_area_clamped_coord( lua_State* L )
|
---|
| 262 | {
|
---|
[207] | 263 | nv::rectangle* a = to_parea( L, 1 );
|
---|
| 264 | nv::ivec2* c = to_pcoord( L, 2 );
|
---|
[454] | 265 | push_coord( L, nv::math::clamp( *c, a->ul, a->lr ) );
|
---|
[176] | 266 | return 0;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | static int nlua_area_fix( lua_State* L )
|
---|
| 270 | {
|
---|
[207] | 271 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[176] | 272 | if ( a->ul.x > a->lr.x ) a->ul.x = a->lr.x;
|
---|
| 273 | if ( a->ul.y > a->lr.y ) a->ul.y = a->lr.y;
|
---|
| 274 | return 0;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | static int nlua_area_proper( lua_State* L )
|
---|
| 278 | {
|
---|
[207] | 279 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[176] | 280 | lua_pushboolean( L, a->ul.x <= a->lr.x && a->ul.y <= a->lr.y );
|
---|
| 281 | return 1;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | static int nlua_area_dim( lua_State* L )
|
---|
| 285 | {
|
---|
[207] | 286 | nv::rectangle* a = to_parea( L, 1 );
|
---|
| 287 | push_coord( L, a->ul - a->lr + nv::ivec2(1,1) );
|
---|
[176] | 288 | return 1;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | static int nlua_area_size( lua_State* L )
|
---|
| 292 | {
|
---|
[207] | 293 | nv::rectangle* a = to_parea( L, 1 );
|
---|
[176] | 294 | lua_pushinteger( L, a->get_enclosed_area() );
|
---|
| 295 | return 1;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | static int nlua_area_contains( lua_State* L )
|
---|
| 299 | {
|
---|
[207] | 300 | lua_pushboolean( L, to_parea( L, 1 )->contains( to_coord( L, 2 ) ) );
|
---|
[176] | 301 | return 1;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | static int nlua_area_is_edge( lua_State* L )
|
---|
| 305 | {
|
---|
[207] | 306 | nv::rectangle a = to_area( L, 1 );
|
---|
| 307 | nv::ivec2 c = to_coord( L, 2 );
|
---|
[176] | 308 | lua_pushboolean( L, a.contains( c ) && ( c.x == a.ul.x || c.x == a.lr.x || c.y == a.ul.y || c.y == a.lr.y ) );
|
---|
| 309 | return 1;
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | static int nlua_area_around( lua_State* L )
|
---|
| 313 | {
|
---|
[207] | 314 | nv::ivec2 c = to_coord( L, 1 );
|
---|
[204] | 315 | int amount = static_cast< int >( lua_tointeger( L, 1 ) );
|
---|
[176] | 316 | nv::ivec2 shift( amount, amount );
|
---|
[207] | 317 | push_area( L, nv::rectangle( c - shift, c + shift ) );
|
---|
[176] | 318 | return 1;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | static int nlua_area_tostring( lua_State* L )
|
---|
| 322 | {
|
---|
[207] | 323 | nv::rectangle a = to_area( L, 1 );
|
---|
[378] | 324 | lua_pushfstring( L, "(%d,%dx%d,%d)", a.ul.x, a.ul.y, a.lr.x, a.lr.y );
|
---|
[176] | 325 | return 1;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | static int nlua_area_random_edge_coord( lua_State* L )
|
---|
| 329 | {
|
---|
[207] | 330 | nv::rectangle area = to_area( L, 1 );
|
---|
[176] | 331 | nv::ivec2 a = area.ul;
|
---|
| 332 | nv::ivec2 b = area.lr;
|
---|
| 333 | nv::sint32 xs = ( b.x - a.x ) + 1;
|
---|
| 334 | nv::sint32 ys = ( b.y - a.y ) - 1;
|
---|
| 335 | nv::sint32 roll = nv::random::get().srand( 2 * xs + 2 * ys );
|
---|
| 336 | nv::ivec2 result;
|
---|
| 337 |
|
---|
| 338 | if ( roll < 2 * xs )
|
---|
| 339 | {
|
---|
| 340 | result = ( roll < xs ) ? nv::ivec2( a.x + roll, a.y ) : nv::ivec2( a.x + roll - xs, b.y );
|
---|
| 341 | }
|
---|
| 342 | else
|
---|
| 343 | {
|
---|
| 344 | roll -= 2 * xs;
|
---|
| 345 | result = ( roll < ys ) ? nv::ivec2( a.x, a.y + roll + 1 ) : nv::ivec2( b.x, a.y + roll - ys + 1);
|
---|
| 346 | }
|
---|
[207] | 347 | push_coord( L, result );
|
---|
[176] | 348 | return 1;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | static int nlua_area_random_inner_edge_coord( lua_State* L )
|
---|
| 352 | {
|
---|
[207] | 353 | nv::rectangle area = to_area( L, 1 );
|
---|
[176] | 354 | nv::ivec2 a = area.ul;
|
---|
| 355 | nv::ivec2 b = area.lr;
|
---|
| 356 | nv::sint32 xs = ( b.x - a.x ) - 1;
|
---|
| 357 | nv::sint32 ys = ( b.y - a.y ) - 1;
|
---|
| 358 | nv::sint32 roll = nv::random::get().srand( 2 * xs + 2 * ys );
|
---|
| 359 | nv::ivec2 result;
|
---|
| 360 |
|
---|
| 361 | if ( roll < 2 * xs )
|
---|
| 362 | {
|
---|
| 363 | result = ( roll < xs ) ? nv::ivec2( a.x + roll + 1, a.y ) : nv::ivec2( a.x + roll - xs + 1, b.y );
|
---|
| 364 | }
|
---|
| 365 | else
|
---|
| 366 | {
|
---|
| 367 | roll -= 2 * xs;
|
---|
| 368 | result = ( roll < ys ) ? nv::ivec2( a.x, a.y + roll + 1 ) : nv::ivec2( b.x, a.y + roll - ys + 1);
|
---|
| 369 | }
|
---|
[207] | 370 | push_coord( L, result );
|
---|
[176] | 371 | return 1;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | static int nlua_area_random_coord( lua_State* L )
|
---|
| 375 | {
|
---|
[207] | 376 | nv::rectangle area = to_area( L, 1 );
|
---|
| 377 | push_coord( L, nv::random::get().range( area.ul, area.lr ) );
|
---|
[176] | 378 | return 1;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | static int nlua_area_random_subarea( lua_State* L )
|
---|
| 382 | {
|
---|
[207] | 383 | nv::rectangle area = to_area( L, 1 );
|
---|
| 384 | nv::ivec2 dim = to_coord( L, 2 );
|
---|
[176] | 385 | nv::ivec2 start = nv::random::get().range( area.ul, area.lr - dim );
|
---|
[207] | 386 | push_area( L, nv::rectangle( start, start + dim ) );
|
---|
[176] | 387 | return 1;
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 |
|
---|
[198] | 391 | static int luaopen_area( lua_State * L )
|
---|
[176] | 392 | {
|
---|
[335] | 393 | NV_LUA_STACK_ASSERT( L, 1 );
|
---|
[176] | 394 | static const struct luaL_Reg nlua_area_sf [] = {
|
---|
| 395 | { "new", nlua_area_new },
|
---|
| 396 | { "around", nlua_area_around },
|
---|
| 397 | {NULL, NULL}
|
---|
| 398 | };
|
---|
| 399 |
|
---|
| 400 | static const struct luaL_Reg nlua_area_f [] = {
|
---|
| 401 | { "get", nlua_area_get },
|
---|
| 402 | { "clone", nlua_area_clone },
|
---|
| 403 |
|
---|
| 404 | { "coords", nlua_area_coords },
|
---|
| 405 | { "edges", nlua_area_edges },
|
---|
| 406 | { "corners", nlua_area_corners },
|
---|
| 407 |
|
---|
| 408 | { "tostring", nlua_area_tostring },
|
---|
| 409 | { "shrink", nlua_area_shrink },
|
---|
| 410 | { "shrinked", nlua_area_shrinked },
|
---|
| 411 | { "expand", nlua_area_expand },
|
---|
| 412 | { "expanded", nlua_area_expanded },
|
---|
| 413 | { "clamp", nlua_area_clamp },
|
---|
| 414 | { "clamped", nlua_area_clamped },
|
---|
| 415 | { "clamp_coord", nlua_area_clamp_coord },
|
---|
| 416 | { "clamped_coord", nlua_area_clamped_coord },
|
---|
| 417 | { "fix", nlua_area_fix },
|
---|
| 418 | { "proper", nlua_area_proper },
|
---|
| 419 | { "dim", nlua_area_dim },
|
---|
| 420 | { "size", nlua_area_size },
|
---|
| 421 | { "contains", nlua_area_contains },
|
---|
| 422 | { "is_edge", nlua_area_is_edge },
|
---|
| 423 |
|
---|
| 424 | { "random_subarea", nlua_area_random_subarea },
|
---|
| 425 | { "random_coord", nlua_area_random_coord },
|
---|
| 426 | { "random_edge_coord", nlua_area_random_edge_coord },
|
---|
| 427 | { "random_inner_edge_coord", nlua_area_random_inner_edge_coord },
|
---|
| 428 |
|
---|
| 429 | {NULL, NULL}
|
---|
| 430 | };
|
---|
| 431 |
|
---|
| 432 | static const struct luaL_Reg nlua_area_sm [] = {
|
---|
| 433 | { "__call", nlua_area_call },
|
---|
| 434 | {NULL, NULL}
|
---|
| 435 | };
|
---|
| 436 |
|
---|
| 437 | static const struct luaL_Reg nlua_area_m [] = {
|
---|
| 438 | { "__eq", nlua_area_eq },
|
---|
| 439 | { "__call", nlua_area_coords },
|
---|
| 440 | { "__index", nlua_area_index },
|
---|
| 441 | { "__newindex", nlua_area_newindex },
|
---|
| 442 | { "__tostring", nlua_area_tostring },
|
---|
| 443 | {NULL, NULL}
|
---|
| 444 | };
|
---|
| 445 |
|
---|
[449] | 446 | luaL_newmetatable( L, nv::lua::pass_traits< nv::rectangle >::metatable() );
|
---|
[176] | 447 | nlua_register( L, nlua_area_m, -1 );
|
---|
| 448 | lua_createtable( L, 0, 0 );
|
---|
| 449 | nlua_register( L, nlua_area_f, -1 );
|
---|
| 450 | lua_setfield(L, -2, "__functions" );
|
---|
| 451 | lua_pop( L, 1 );
|
---|
| 452 |
|
---|
| 453 | lua_createtable( L, 0, 0 );
|
---|
| 454 | nlua_register( L, nlua_area_sf, -1 );
|
---|
| 455 | lua_createtable( L, 0, 0 );
|
---|
| 456 | nlua_register( L, nlua_area_sm, -1 );
|
---|
| 457 | lua_setmetatable( L, -2 );
|
---|
| 458 | return 1;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[207] | 461 | void nv::lua::register_area( lua_State* L )
|
---|
[176] | 462 | {
|
---|
| 463 | int stack = lua_gettop( L );
|
---|
| 464 | luaL_requiref(L, "area", luaopen_area, 1);
|
---|
| 465 | lua_settop( L, stack );
|
---|
| 466 | }
|
---|
| 467 |
|
---|