Skip to content

Instantly share code, notes, and snippets.

@grandemk
Last active September 30, 2018 00:06
Show Gist options
  • Save grandemk/3efd707fb77a1332f45e9839b650f0a1 to your computer and use it in GitHub Desktop.
Save grandemk/3efd707fb77a1332f45e9839b650f0a1 to your computer and use it in GitHub Desktop.
#include "sol.hpp"
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
sol::state lua;
string code = "unknown_func()";
sol::coroutine co = lua.load(code);
while(co)
{
cout << "C++ - Resuming coroutine" << endl;
auto result = co();
cout << "C++ Coroutine state: " << sol::to_string(co.status()) << std::endl;
// how do I get the error string ?
// answer:
if(!result.valid())
sol:error err = result;
cout << "error: " << err.what() << endl
}
}
@grandemk
Copy link
Author

grandemk commented Sep 29, 2018

$ g++ -std=c++14 coroutine_error_handling.cpp ext/liblua.a -I ext/lua-5.3.5/src -ldl
$ ./a.out
C++ - Resuming coroutine
C++ Coroutine state: runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment