[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua: Multithreading, Precompiled Chunks
- From: lhf (Luiz Henrique de Figueiredo)
- Date: Sat, 7 Mar 1998 10:49:14 -0300
>From ashley@bmarket.com Sat Mar 7 06:20:30 1998
>
>Does anyone have experience using Lua in a multithreaded environment? I
>would like to run several low-priority threads simultaneously, each with
>their own Lua script. Is there anything in Lua that would break? I don't
>have any need for interprocess communication, just that nothing Lua-global
>breaks. Suggestions?
Some people have changed Lua to work in a multithreaded environment.
Lua 3.1 has support for multiple environments, with a single global variable
pointing to the current environment. This should help using Lua in
a multithreaded environment.
>Second, is there some way to run a pre-compiled binary chunk directly from
>memory rather than from a file? I would like to link some pre-compiled
>chunks directly into my executable, and then have Lua execute them.
> Possible?
Lua 3.1 has an undocumented function lua_dobuffer that does this.
I think we'll make lua_dobuffer part of the official API when 3.1 is released.
Below, is a simple program that converts binary files to byte arrays that I
think will be useful to you.
>Lastly, is there an archive of the messages from this mailing list
>somewhere? I'd love to read the old traffic.
Everything is saved here but I don't know whether the list server is putting
out archives. Try sending 'help' to listproc@tecgraf.puc-rio.br.
If we cannot do this, I'll consider putting a link to it in the web pages.
--lhf
/*
* bin2c.c
* convert binary files to byte arrays
* Luiz Henrique de Figueiredo (lhf@tecgraf.puc-rio.br)
* 12 Jan 98 10:55:22
*/
#include <stdio.h>
void dump(FILE* f, char* name)
{
int n;
printf("/* %s */\nstatic unsigned char B_",name);
for (;*name; name++)
{
if (isalnum(*name)) putchar(*name); else putchar('_');
}
printf("[]={\n");
for (n=1;;n++)
{
int c=getc(f);
if (c==EOF) break;
#if 0
printf("0x%02x,",c);
#else
printf("%3u,",c);
#endif
if (n==20) { putchar('\n'); n=0; }
}
printf("\n};\n\n");
}
void fdump(char* fn)
{
FILE* f=fopen(fn,"rb"); /* must open in binary mode */
if (f==NULL)
{
fprintf(stderr,"bin2c: cannot open ");
perror(fn);
exit(1);
}
else
{
dump(f,fn);
fclose(f);
}
}
void main(int argc, char* argv[])
{
if (argc<2)
{
dump(stdin,"stdin");
}
else
{
while (--argc>0)
fdump(*++argv);
}
}