sol2/examples/source/tutorials/lazy_demo.cpp

24 lines
433 B
C++
Raw Normal View History

#define SOL_ALL_SAFETIES_ON 1
2019-07-04 23:16:03 +08:00
#include <sol/sol.hpp>
2018-11-10 06:36:27 +08:00
#include <iostream>
int main() {
sol::state lua;
auto barkkey = lua["bark"];
if (barkkey.valid()) {
// Branch not taken: doesn't exist yet
std::cout << "How did you get in here, arf?!" << std::endl;
}
barkkey = 50;
if (barkkey.valid()) {
// Branch taken: value exists!
std::cout << "Bark Bjork Wan Wan Wan" << std::endl;
}
return 0;
}