[英]SWIG Lua and passing arrays
我目前有以下lua代码:
g = engine.CGeometry()
vertexes = {}
vertexes[1] = 0
vertexes[2] = 0
vertexes[3] = 0
vertexes[4] = 0
vertexes[5] = -1
vertexes[6] = 0
vertexes[7] = -1
vertexes[8] = 0
vertexes[9] = 0
print "adding vertexes"
g:SetVertexes(vertexes)
其中g:SetVertexes()在C ++中实现为:
void CGeometry::SetVertexes(double* vertexes){
this->vertexes = vertexes;
}
导致此错误:
adding vertexes
PANIC: unprotected error in call to Lua API (Error in SetVertexes (arg 2), expected 'double *' got 'table')
Press any key to continue . . .
有任何想法吗?
试着写:
void CGeometry::SetVertexes(double vertexes[]);
在接口定义中。 从文档来看,SWIG在指针和数组之间做出了区别。
你可以在这里描述carrays.i模块: http ://www.swig.org/Doc1.3/Library.html
例如,你在C ++中有这样的功能:
void fun(double arr[]) { }
然后在.i文件中加载模块:
%include "carrays.i"
%array_functions(double, doubleArray);
void fun(double arr[]);
在Lua脚本中:
a = new_doubleArray(10) # Create an array
doubleArray_setitem(a,0,5.0) # Set value 5.0 on index 0
fun(a) # Pass to C
delete_doubleArray(a) # Destroy array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.