Skip to content

Instantly share code, notes, and snippets.

@CinchBlue
Created April 3, 2015 02:35
Show Gist options
  • Save CinchBlue/86c2612bd9e88e572dda to your computer and use it in GitHub Desktop.
Save CinchBlue/86c2612bd9e88e572dda to your computer and use it in GitHub Desktop.
Sol file doesn't compile? Hm.
#include <iostream>
#include <string>
#include <sstream>
#include "lua.hpp"
#include "sol.hpp"
#include "Flexiglass.hpp"
template <typename T>
T unpack (boost::any& b)
{
T result = boost::any_cast<T>(b);
return result;
}
int main()
{
sol::state lua;
lua.open_libraries(sol::lib::base);
//Set boost::any object to a std::string value and pass it to Lua.
boost::any obj(std::string("hello"));
//This syntax should work here. I did a test case with a templated function.
lua.set_function("unpack", unpack<std::string>);
//Contents:
//print('Hello World!')
//unpack(b)
lua.open_file("test.lua");
//The program outputs "Hello World"
//But fails at the unpack() method.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment