int main()
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
if (luaL_dofile(L,"func.lua") != 0)
{
std::cout<<"Load Lua File Error"<<std::endl;
}
int numElements = 100;
float *mydata = new float[numElements];
THFloatStorage *mystorage = THFloatStorage_newWithData(mydata, numElements);
THFloatTensor* mytensor = THFloatTensor_newWithStorage1d(mystorage, 0, numElements, 1);
lua_getglobal(L,"testTensor"); //testTensor
【const char* torch_Tensor_id = luaT_typenameid(L, "torch.Tensor");】——which got SegmentFault when running:
//luaT_newmetatable(L, "torch.Tensor", NULL, NULL, NULL, NULL);——which got SegmentFault when running as well:
luaT_pushudata(L, (void *)mytensor, torch_Tensor_id);
lua_call(L,1,1);
delete[] mydata;
return 0;
}