matthias | 4 Jul 09:30

strange behaviour with luaL_checkinteger()

Hi all,

I wrote my own Lua-crc function and got some weired results. For
proofing correctness I also implemented a c-program.
But when the c-program returned a negative value (with %d) I got a
different value from the Lua-library.

My algorithm is quite similar to the one from lash-lua:
http://code.google.com/p/lash-lua/source/browse/trunk/crc32.c?spec=svn5&r=5#112

Although I got the data with the luaL_checkinteger()-function.
Seems that there lies the problem, but I don't get what I've done wrong.
Inside Lua every number is a floating-point. So when I call my library
function from a Lua-script I pass the value converting it to a number.
Therefore a floatingpoint number should be on the stack and I "cast "
it into my c- integer variable with the check integer-function.
But representation of integer-values shouldn't be a problem
(http://lua-users.org/wiki/FloatingPoint).
In the c-program I pass the value via atoi()-function call from argv[]
which shouldn't be a problem, too.

Can anyone give me a hint, what I am missing.

Thanks
Matthias

--

-- 
motzblog.wordpress.com

(Continue reading)

David Manura | 4 Jul 05:35
Favicon

possible bug in lua.c main report lua_tostring malloc

In Lua 5.1.4, in lua.h:main, the call to "report" invokes
lua_tostring, which according to the Lua Reference Manual may raise a
memory error, presumably in the condition where the error value is a
number that must be translated into a string and therefore allocate
memory for the string.  In this context, the call to lua_tostring is
unprotected.

I was able to cause "lua -e 'error(5)'" to crash by triggering an
allocation failure in lmem.c:

--- src/lmem.c~
+++ src/lmem.c
@@ -74,9 +74,11 @@
 ** generic allocation routine.
 */
 void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
+  static int count = 0;
   global_State *g = G(L);
   lua_assert((osize == 0) == (block == NULL));
   block = (*g->frealloc)(g->ud, block, osize, nsize);
+  if (nsize > osize && ++count > 450) luaD_throw(L, LUA_ERRMEM);
   if (block == NULL && nsize > 0)
     luaD_throw(L, LUA_ERRMEM);
   lua_assert((nsize == 0) == (block == NULL));

BTW, the following type of code is probably fairly common for users to
include at the top level C stack:

  if (lua_cpcall(L, f, NULL) != 0) {
    fprintf(stderr, "%s\n", lua_tostring(L, -1) ? lua_tostring(L, -1)
(Continue reading)

Norbert Kiesel | 4 Jul 02:44

lpeg question

Hi,

I started to play around a bit with lpeg and found a (for me) suprising
behavior: the following lua code

lpeg=require"lpeg"
require"re"
print("lpeg version", lpeg.version())
x = {re.find('hello', [[ { 'h' . . } { . } { . }  -> {} ]])}
print(type(x), #x, x[1], x[2], x[3], x[4])
print(type(x[4]), #x[4], x[4][1])

prints

lpeg version	0.8
table	4	1	hel	l	table: 0x6c7710
table	1	o

I would have expected to get

lpeg version	0.8
table	4	1	hel	l	o
string	1	nil

why is the last capture returned as a table?

</nk>

Hans van der Meer | 3 Jul 17:17
Favicon

XCode template for lua modules

Working on a Macintosh under MacOSX I am trying to get the XCode build settings in shape for compilation of a Lua C-module into module.so; starting with the XCode-template for a BSD dynamic library.

Having read the instructions for using make I have the following question:

Why does one prescribe for the Mach-O Type the choice "bundle" (mh_bundle) instead of "dynamic library" (mh_dylib). Both seem to work when the result is "require"-ed. Does it matter? Or is there a fundamental difference I am overlooking?

Hans van der Meer




Andre Carregal | 3 Jul 17:04

LuaForge temporarily out of reach

LuaForge's ISP is going through some maintenance services and the site
will be down for the next 2 hours. The server is still up, just out of
reach.

André

kino | 3 Jul 14:05

Lua Workshop 2008 Videos

Hi Lua community,

Last year I made videos of some of the Lua Workshop 2008 presentation.  
I learned a lot about Lua making these videos and was even able to use  
Lua for my Masters thesis which I successfully defended last month. I  
posted these videos to Vimeo and my university server.

At Vimeo it is possible to download these videos in the form which I  
uploaded them by simply making an account with an email address and  
clicking a link on the bottom of the page for each video. I still had  
to compress them a bit because they are all quite long and there is an  
upload data limit. Vimeo compressed them again in order to stream them.

Vimeo is now changing its policy for the basic free accounts that they  
will delete the original uploads and only keep their compressed  
streaming version available for download. This will take effect August  
1 and I thought I would let the Lua community know in case people are  
interested in downloading them before then. I think there may be a  
limit on the number of downloads per video file per day, so if you  
encounter some limit simply wait 24 hours if this is the case. You can  
find the videos on Vimeo here:

http://www.vimeo.com/tag:luaworkshop

and at the university server here:

http://v.poly.edu/stories/Lua

Please note that both sites operate with flash player.

Cheers

Jeremy Schaller

steve donovan | 3 Jul 14:01

Inling C/Fortran in Lua

Of course, luatcc does this already, but does not free you from having
to write the binding code, such as would be generated by tolua++.

Inling performance-critical code can be an effective trick:

http://on-ruby.blogspot.com/2006/07/rubyinline-making-making-things-faster.html

Now the question is, is it worth pursuing this for Lua?  tolua++ works
rather nicely, but you have to maintain a separate .c/.cpp file and
hand-roll the .pkg file (the cleaned header).  So, for
proof-of-concept, I'd build on tolua++.  After the first compile, a
quick dependency check means that the inlined code need not be
recompiled.  One has to make sure that the .so/.dll is loadable from
the same location as the original Lua file, etc.

I've been generally thinking about Lua and High-Performance Computing.
 A library like this, plus MPI bindings, and one has a means to write
very effective parallelized programs in a nicer language than FORTRAN.
 Actually, modern FORTRAN is a good companion to Lua in this context,
since it's cleaner and faster than C, especially for things like bulk
array operations and complex arithmetic.

Any thoughts?

steve d.

Peter Jacobi | 3 Jul 09:40

Lua for MediaWiki?

Just FYI: There is a discussion on the wikitech-l mailing list,
whether to replace MediaWiki's current templating system (a
Turing-complete language uglier than PERL) with Lua (or other
options). Lua could gain some millions of new users by this...

Peter

Leo Razoumov | 2 Jul 23:00

lfs (CVS version) compilation error under Ununtu-9.04 Jaunty

Unfortunately, lfs CVS version (src/lfs.c revision 1.60) does not compile under
Linux Ubuntu-9.04 (jaunty) x86, kernel 2.6.28, gcc-4.3.3, glibc-2.9.

src/lfs.c: In function ‘lfs_lock_dir’:
src/lfs.c:278: error: ‘struct stat’ has no member named ‘st_mtimespec’
gcc -O2 -I/pkg/lua-5.1.4.LR2/include -c src/lfs.c -o src/lfs.o

Error: Build error: Build error

Indeed, neither /usr/include/sys/stat.h nor /usr/include/bits/stat.h define
st_mtimespec member of struct stat. POSIX compliant name should be st_mtime.

Simple patch below fixed the problem for me.

--Leo--

--------%<--------%<--------%<--------
diff --git a/src/lfs.c b/src/lfs.c
index 13562ee..d96ca38 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -275,7 +275,7 @@ static int lfs_lock_dir(lua_State *L) {
    while(symlink(tmpln, ln) == -1) {
      if(errno == EEXIST) {
        if(lstat(ln, &statbuf) == -1) goto fail;
-      if(time(NULL) - statbuf.st_mtimespec.tv_sec > expires) {
+      if(time(NULL) - statbuf.st_mtime > expires) {
  		unlink(ln);
  		continue;
        }
-------->%-------->%-------->%--------
Phoenix Sol | 2 Jul 21:52
Gravatar

Tyrant Client?

Anybody have a Lua client for Tokyo Tyrant?

(  For this:  http://code.google.com/p/luacloud  )

Thanks a heap,
Phoenix Sol

Thomas Lauer | 2 Jul 13:03
Favicon

[ANN] Lua Short Reference, minor upgrade

The Lua short reference provides a concise summary of the Lua syntax and
core libraries. I have just updated and uploaded another draft of the
5.1 version. This can be downloaded from either the lua-users.org wiki:

http://lua-users.org/wiki/LuaShortReference

or from my website:

http://thomaslauer.com/comp/Lua_Short_Reference

A few small errors and inconsistencies were removed. However, there are
certainly still errors and omissions to be found in this draft. PLEASE,
everyone who uses this card -- take the time and trouble to send a bug
report if you happen on something that needs correcting. (BTW, the
exclusion of deprecated language features (like table.setn()) is by
design.)

Acknowledgements: Enrico Colombini (the original author) and I are
grateful to all the good people who contributed with notes and
suggestions, including John Belmonte, Albert-Jan Brouwer, Tiago
Dionizio, Marius Gheorghe, Asko Kauppi, Philippe Lhoste, Mike Pall,
Virgil Smith, Ando Sonenblick, Nick Trout, Clemens Wacha, Blake T.
Garretson, mbp, James Salsman and of course Roberto Ierusalimschy, whose
“Lua 5.1 Reference Manual” and “Programming in Lua” have been our main
sources of Lua lore.

--

-- 
cheers  thomasl

web : http://thomaslauer.com/start


Gmane