453 |
463 |
454 |
464 |
455 /** |
465 /** |
456 * SSL metamethods |
466 * SSL metamethods |
457 */ |
467 */ |
458 static luaL_Reg meta[] = { |
468 static luaL_Reg methods[] = { |
459 {"close", meth_close}, |
469 {"close", meth_close}, |
460 {"getfd", meth_getfd}, |
470 {"getfd", meth_getfd}, |
461 {"dirty", meth_dirty}, |
471 {"dirty", meth_dirty}, |
462 {"dohandshake", meth_handshake}, |
472 {"dohandshake", meth_handshake}, |
463 {"receive", meth_receive}, |
473 {"receive", meth_receive}, |
481 {"rawconnection", meth_rawconn}, |
491 {"rawconnection", meth_rawconn}, |
482 {NULL, NULL} |
492 {NULL, NULL} |
483 }; |
493 }; |
484 |
494 |
485 /** |
495 /** |
|
496 * Context metamethods. |
|
497 */ |
|
498 static luaL_Reg meta[] = { |
|
499 {"__gc", meth_destroy}, |
|
500 {"__tostring", meth_tostring}, |
|
501 {NULL, NULL} |
|
502 }; |
|
503 |
|
504 /** |
486 * Initialize modules |
505 * Initialize modules |
487 */ |
506 */ |
488 LUASEC_API int luaopen_ssl_core(lua_State *L) |
507 LUASEC_API int luaopen_ssl_core(lua_State *L) |
489 { |
508 { |
490 /* Initialize SSL */ |
509 /* Initialize SSL */ |
497 /* Initialize internal library */ |
516 /* Initialize internal library */ |
498 socket_open(); |
517 socket_open(); |
499 |
518 |
500 /* Register the functions and tables */ |
519 /* Register the functions and tables */ |
501 luaL_newmetatable(L, "SSL:Connection"); |
520 luaL_newmetatable(L, "SSL:Connection"); |
|
521 luaL_register(L, NULL, meta); |
|
522 |
502 lua_newtable(L); |
523 lua_newtable(L); |
503 luaL_register(L, NULL, meta); |
524 luaL_register(L, NULL, methods); |
504 lua_setfield(L, -2, "__index"); |
525 lua_setfield(L, -2, "__index"); |
505 lua_pushcfunction(L, meth_destroy); |
|
506 lua_setfield(L, -2, "__gc"); |
|
507 |
526 |
508 luaL_register(L, "ssl.core", funcs); |
527 luaL_register(L, "ssl.core", funcs); |
509 lua_pushnumber(L, SOCKET_INVALID); |
528 lua_pushnumber(L, SOCKET_INVALID); |
510 lua_setfield(L, -2, "invalidfd"); |
529 lua_setfield(L, -2, "invalidfd"); |
511 |
530 |