It seems unclear to me as to how to deal with variables that do not exist in the lua state. This combined with issue #41 means that lots of things can go bad without the user being informed. I think the correct behaviour here would be an exception, as int cannot be NULL. However it has been noted in #10 that exceptions are not going to be used so I am not sure how to proceed.
$ lua
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> print(y)
nil
>
#include "Selene/include/selene.h"
#include <string>
#include <iostream>
int main(void) {
sel::State state;
state["x"] = 0;
state["y"] = std::string("");
int x = state["x"];
int x2 = state["x2"]; // this doesn't exist
std::string y = state["y"];
std::string y2 = state["y2"]; // this doesn't exist
std::cout << (x == x2 ? "same" : "different") << std::endl;
std::cout << (y == y2 ? "same" : "different") << std::endl;
return 0;
}
$ g++-4.9 -std=c++11 -g -I/usr/include/lua5.2 test.cpp -llua5.2 -o test
$ ./test
same
same
$
It seems unclear to me as to how to deal with variables that do not exist in the lua state. This combined with issue #41 means that lots of things can go bad without the user being informed. I think the correct behaviour here would be an exception, as
intcannot be NULL. However it has been noted in #10 that exceptions are not going to be used so I am not sure how to proceed.