| 676 | // *********************************************************************** |
| 677 | |
| 678 | void BindUserData(lua_State* L) { |
| 679 | |
| 680 | // register global functions |
| 681 | const luaL_Reg globalFuncs[] = { |
| 682 | { "userdata", NewUserData }, |
| 683 | { "vec", NewVec }, |
| 684 | { "quat", NewQuat }, |
| 685 | { NULL, NULL } |
| 686 | }; |
| 687 | |
| 688 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 689 | luaL_register(L, NULL, globalFuncs); |
| 690 | lua_pop(L, 1); |
| 691 | |
| 692 | // new metatable |
| 693 | luaL_newmetatable(L, "UserData"); |
| 694 | |
| 695 | // register metamethods |
| 696 | const luaL_Reg bufferMethods[] = { |
| 697 | { "__index", Index }, |
| 698 | { "__newindex", NewIndex }, |
| 699 | { "__tostring", ToString }, |
| 700 | { "__add", Add }, |
| 701 | { "__sub", Sub }, |
| 702 | { "__mul", Mul }, |
| 703 | { "__div", Div }, |
| 704 | { "set", Set }, |
| 705 | { "set2D", Set2D }, |
| 706 | { "get", Get }, |
| 707 | { "get2D", Get2D }, |
| 708 | { "width", Width }, |
| 709 | { "height", Height }, |
| 710 | { "size", Size }, |
| 711 | { "magnitude", VecMagnitude }, |
| 712 | { "distance", VecDistance }, |
| 713 | { "dot", VecDot }, |
| 714 | { NULL, NULL } |
| 715 | }; |
| 716 | |
| 717 | // TODO: some future functionality that might be useful: |
| 718 | // Cross product |
| 719 | // more fancy operations such as using strides, offsets, scalar against buffer etc |
| 720 | // helpers for treating buffers as matrices, matmul functions, transpose, inverse etc |
| 721 | |
| 722 | luaL_register(L, NULL, bufferMethods); |
| 723 | lua_pop(L, 1); |
| 724 | } |
no outgoing calls
no test coverage detected