sol2/examples/require_dll_example/my_object.cpp
ThePhD 03c229b25b overhaul examples and add 2 new ones in preparation for the coming hell
fix how `stack_aligned_protected_function` and its friends behave
add new internal handler details to allow for stack-based handlers with maximum performance
update `string_shim` typedef to simply be called `string_view` and use `string_view` in all public-facing APIs.
2017-08-06 12:20:32 -04:00

29 lines
745 B
C++

#include "my_object.hpp"
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
namespace my_object {
sol::table open_my_object(sol::this_state L) {
sol::state_view lua(L);
sol::table module = lua.create_table();
module.new_usertype<test>("test",
sol::constructors<test(), test(int)>(),
"value", &test::value
);
return module;
}
} // namespace my_object
extern "C" int luaopen_my_object(lua_State* L) {
// pass the lua_State,
// the index to start grabbing arguments from,
// and the function itself
// optionally, you can pass extra arguments to the function if that's necessary,
// but that's advanced usage and is generally reserved for internals only
return sol::stack::call_lua(L, 1, my_object::open_my_object );
}