Closed blackmetal closed 10 years ago
Thanks for the report. Unfortunately I can't reproduce.
What compiler version are you using?
Just a guess, but CodeBlocks recommends GCC 4.7.1 with its default CodeBlocks 13.12 installer.
If that's the case, you might need to explicitly pass the -std=c++11 to CodeBlock's compiler settings to make sure it's properly able to handle some of the later features.
I would also recommend downloading and using the codeblocks-13.12mingw-setup-TDM-GCC-481.exe
version, since GCC 4.8.1 is the latest and greatest and starting out on an older version doesn't help you at all.
I'm currently using the gcc
Ok, so now i'm in gcc 4.8.1 version, i get a segfault when i run the same script i posted above (it compiles, first victory!) The segfault is on that line:
assert(lua.get<vars>("beep").boop = 1);
It's not the assert that makes the error (i tried to remove the assert and stored the lua.get
Okay. Now I can reproduce. Apparently, I forgot I was building with 'Release' last time. The build is definitely failing on my end.
This is also a possible duplicate of #25 and #35 which have their own test case and pass them just fine.
Turns out this is a clerical error: the front page/examples should be fixed and this should be registered as not-a-bug.
int main() {
sol::state lua;
lua.new_userdata<vars>("vars", "boop", &vars::boop);
lua.script("local beep = vars.new()\n"
"beep.boop = 1");
assert(lua.get<vars>("beep").boop == 1);
}
Notice in the snippet that there is local beep = ...
, then the rest of the code.
local
means that variable is inaccessible outside of its scope. It's not stored in the global lua table once the script is done running: it's made inaccessible and marked for garbage collection.
So it's actually behaving as it should be. Remove the local
and it'll do what you want.
[ Extra Nitpicky Notes ]
As a final warning, make sure you get the value with auto&
if you care about not making a copy, as auto
just resolves to vars
and if you do vars my_vars = lua.get<vars>("beep");
, whatever you have will be a copy from lua, not a reference to the actual data.
Ok :) Thanks for the answer.
Hi, I'm totally new to sol, so maybe my compiling error is stupid. I'm working on Windows 64 bits (compiling in 32 bits) with Code::Blocks 13.12. I recompiled lua 5.2.3 like 10 minutes ago.
This simple code won't compile:
When i use a simple examples (basic.cpp or variables.cpp), the code compile and works as expected but when i use the set_function or new_userdata functions like in the code above, i get the following error:
Can someone tell me what i did wrong? Thanks a lot in advance :)