Original Post
Hi: my lua script is: i want to call script in the rendering loop; at same time i register the function of GetCurrentPos and then load lua file before rendering; the calling script codes are: the relative script code are belown: but the error information is: why? anybody help me? thank you very much!
ForceInfo = {ForceStrength = 20000, ForceDirX = 1, ForceDirY = 0, ForceDirZ = 0}
function DecideForceInfo()
curPosx, curPosz = GetCurrentPos()
if(curPosx >= 0.0) then
print("Stop Now")
ForceInfo.ForceStrength = 0.0
else
print("Now position of x is" .. curPosx)
end
end
lua_getglobal(luaVM, "ForceInfo");
DecideForceInfo();
gForceStrength1 = getfield("ForceStrength");
gForceDir.x = getfield("ForceDirX");//get the key value of table
gForceDir.y = getfield("ForceDirY");
gForceDir.z = getfield("ForceDirZ");
int GetCurrentPos(lua_State *L)
{
lua_pushnumber(L, curpos.x);
lua_pushnumber(L, curpos.z);
/* return the number of results */
return 2;
}
void DecideForceInfo()
{
lua_getglobal(luaVM, "DecideForceInfo");
lua_call(luaVM, 0, 0);
}
stack traceback:
1: function 'GetCurrentPos' [c]
2: function \DecideForceInfo'