The end of array mark is added by lua52.pas, if you read the source code...  My 
problem is solved if I remove the overloaded luaL_newlib function and use only 
the original pointer version, i.e.

var lib: array of luaL_Reg;
luaL_newlib(L, PluaL_Reg(lib));

It seems that while converting from dynamic array to pointer, the compiler 
knows to point to the first element of the array, not the structure.  Could 
anyone confirm this behavior?

The remaining problems are: 1) why the lupas program works well even with the 
problematic overloaded version?  I tested on Windows 7 (32bit), both programs 
failed.  2) I will email the author of lua52.pas to investigate the overloaded 
functions, and personally I will suggest to not use overloading at all.

Shannon

在 六, 12月 29, 2012 at 9:39 下午,leledumbo <[email protected]> 写道:
Reading luaL_newlib documentation and lua52.pas implementation of it (it's a 
macro in the original C code), I see that you need a sentinel value to mark 
the end of the array by putting nil in the name part. I was already skeptic 
since the API doesn't mention the number of elements in the array as 
commonly required by a C function. 



-- 
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-SEGFAULT-difference-between-pointer-and-dynarray-tp4028296p4028310.html
 
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com. 

-- 
_______________________________________________ 
Lazarus mailing list 
[email protected] 
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to