<font face="monospace">Hi All,</font><div><font face="monospace"><br></font></div><div><font face="monospace">I encountered a strange problem with lua integration. &nbsp;Following is the problematic part (full source attached):</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">type</font></div><div><font face="monospace">&nbsp; TluaLReg = array of luaL_Reg;</font></div><div><font face="monospace">var</font></div><div><font face="monospace">&nbsp; LUA: Plua_State;</font></div><div><span style="font-family: monospace; "><b>&nbsp; <font color="#cc0000">lib : array of luaL_Reg;</font></b></span></div><div><font face="monospace"><b>&nbsp; <font color="#204a87">//lib : PluaL_Reg;</font></b></font></div><div><font face="monospace">&nbsp; i: Integer;</font></div><div><font face="monospace">implementation</font></div><div><font face="monospace">//omitted, see attached source...</font></div><div><font face="monospace">initialization</font></div><div><span style="font-family: monospace; ">LUA := luaL_newstate();</span></div><div><font face="monospace">luaL_openlibs(LUA);</font></div><div><font face="monospace" color="#cc0000"><b>SetLength(lib, 2);</b></font></div><div><font face="monospace" color="#204a87"><b>//SetLength(TluaLReg(lib), 2);</b></font></div><div><span style="font-family: monospace; ">lib[0].name := 'update';</span></div><div><font face="monospace">lib[0].func := @l_dat_upd;</font></div><div><font face="monospace">lib[1].name := 'clear';</font></div><div><font face="monospace">lib[1].func := @l_dat_clr;</font></div><div><font face="monospace">luaL_newlib(LUA, lib); &nbsp; &nbsp; &nbsp;<font color="#cc0000"><b>&lt;--Access Violation Here</b></font></font></div><div><font face="monospace">lua_setglobal(LUA, 'data');</font></div><div><font face="monospace">finalization</font></div><div><font face="monospace">lua_close(LUA);</font></div><div><span style="font-family: monospace; ">end.</span></div><div><font face="monospace">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div><div><font face="monospace">The above code caused access violation, unless I use the commented <font color="#204a87"><b>blue</b></font> code to replace the <font color="#cc0000"><b>red</b></font> code. &nbsp;I wonder what's the difference between PluaL_Reg and array of luaL_Reg?? &nbsp;What's more strange is that the same code is OK after I copied it to a separate console mode application. &nbsp;In the attached archive, there are both the problematic project and the OK project.</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">In LUA manual about luaL_newlib(), it said, the 2nd parameter (lib) must be an array not pointer to an array. &nbsp; I am confused what happened here and further more, what's the underlying structure of a normal array in FP (If I am correct, dynamic array is same as pointer, at least that's what I learned in Delphi).</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">My environment is 64 bit Linux 3.5.0 (Mint 14).</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Thanks a lot.</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Sincerely,</font></div><div><font face="monospace">Shannon</font></div><div><font face="monospace"><br></font></div>