关于C#:lua_getglobal崩溃程序

lua_getglobal crashing program

我之前写过一篇有关尝试从C调用lua函数的文章。您可以在这里查看:

Lua:加载文件后获取全局功能失败

如您所见,我正在加载lua文件,然后尝试获取该函数并对其进行调用。一位读者建议我针对该问题的解决方案是更改为dofile而不是加载文件,因为您需要执行脚本才能访问这些功能。但这不是眼前的问题...

无论使用dofile还是loadfile,当我调用lua_getglobal(L," abc");
我的程序崩溃了...

呼叫栈:

1
2
3
4
>   Translation.exe!luaS_newlstr(lua_State * L=0xcccccccc, const char * str=0x00460924, unsigned int l=3)  Line 84 + 0x3 bytes  C
    Translation.exe!lua_getfield(lua_State * L=0xcccccccc, int idx=-10002, const char * k=0x00460924)  Line 551 + 0x20 bytes    C
    Translation.exe!LanguageShovel::FileFound(std::basic_string<char,std::char_traits<char>,std::allocator<char> > path="C:\\Loud\
esolution\\orchid\\source\\EAWResolutionApplication.cpp"
)  Line 32 + 0x16 bytes  C++

崩溃于:

1
2
3
  for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
       o != NULL;
       o = o->gch.next) {

Lua库中的lstring.c文件中的

。我不知道这个lua源代码到底发生了什么。您认为这可能是lua的错误吗?还是我只是做错了?

运行:Windows xp 32位。


L=0xcccccccc提示您没有将Lua状态变量正确传递给此函数(或者它在您的lua_openlua_getglobal调用之间丢失了)。