2019-05-22 07:17:31 +08:00
|
|
|
#define SOL_ALL_SAFETIES_ON 1
|
2018-09-28 13:27:38 +08:00
|
|
|
#include <sol/sol.hpp>
|
2017-08-06 07:20:28 +08:00
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
#include <my_object/my_object.hpp>
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main(int, char*[]) {
|
2018-03-16 05:16:28 +08:00
|
|
|
std::cout << "=== require from DLL ===" << std::endl;
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
sol::state lua;
|
2018-02-08 13:40:34 +08:00
|
|
|
lua.open_libraries(sol::lib::package, sol::lib::base);
|
2017-08-06 07:20:28 +08:00
|
|
|
|
2018-02-08 13:40:34 +08:00
|
|
|
const auto& code = R"(
|
2017-08-06 07:20:28 +08:00
|
|
|
mo = require("my_object")
|
|
|
|
|
|
|
|
obj = mo.test.new(24)
|
2018-02-08 13:40:34 +08:00
|
|
|
print(obj.value))";
|
2021-03-06 23:14:48 +08:00
|
|
|
auto script_result
|
|
|
|
= lua.safe_script(code, &sol::script_pass_on_error);
|
2018-02-08 13:40:34 +08:00
|
|
|
if (script_result.valid()) {
|
2021-03-06 23:14:48 +08:00
|
|
|
std::cout << "The DLL was require'd from successfully!"
|
|
|
|
<< std::endl;
|
2018-02-08 13:40:34 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sol::error err = script_result;
|
2021-03-06 23:14:48 +08:00
|
|
|
std::cout << "Something bad happened: " << err.what()
|
|
|
|
<< std::endl;
|
2018-02-08 13:40:34 +08:00
|
|
|
}
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(script_result.valid());
|
2017-08-06 07:20:28 +08:00
|
|
|
my_object::test& obj = lua["obj"];
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(obj.value == 24);
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
return 0;
|
2022-09-28 13:56:26 +08:00
|
|
|
}
|