2017-08-06 07:20:28 +08:00
|
|
|
#define SOL_CHECK_ARGUMENTS 1
|
|
|
|
#include <sol.hpp>
|
|
|
|
|
|
|
|
#include "my_object.hpp"
|
2017-12-26 14:11:09 +08:00
|
|
|
#include "../assert.hpp"
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main(int, char*[]) {
|
|
|
|
std::cout << "=== require from DLL example ===" << std::endl;
|
|
|
|
|
|
|
|
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))";
|
|
|
|
auto script_result = lua.safe_script(code, &sol::script_pass_on_error);
|
|
|
|
if (script_result.valid()) {
|
|
|
|
std::cout << "The DLL was require'd from successfully!" << std::endl;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sol::error err = script_result;
|
|
|
|
std::cout << "Something bad happened: " << err.what() << std::endl;
|
|
|
|
}
|
|
|
|
c_assert(script_result.valid());
|
2017-08-06 07:20:28 +08:00
|
|
|
my_object::test& obj = lua["obj"];
|
2017-12-26 12:27:22 +08:00
|
|
|
c_assert(obj.value == 24);
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|