lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I just finished porting lua 5.1 to the Playstation 3. Overall, it was very
easy; the port only took an hour or so. The biggest problem was that the PS3
does not have <stdio.h> (more accurately, its <stdio.h> only defines the
function printf()). That means that tmpnam() and tmpfile() does not exist on
the PS3. Lua in general is pretty good about wrapping platform-specific
functions, but tmpfile() was missed, so I added lua_tmpfile() to luaconf.h:

/*
@@ lua_tmpfile will return a pointer to a temporary file's stream
** CHANGE it if you have a way to implement them in your system.
*/

#if defined(LUA_PS3)

#define lua_tmpfile(L) \
	(luaL_error(L, LUA_QL("tmpfile") " not supported"), (FILE*)0)

#else

#define lua_tmpfile(L)	((void)L, tmpfile())

#endif

(I added a LUA_PS3 define as well so the PS3-specific code can be wrapped;
it is defined thus:

#if defined(__CELLOS_LV2__)
#define LUA_PS3
#endif

)

The call to tmpfile() in liolib.c was then replaced by lua_tmpfile(L).

I also had to modify lua_tmpnam() to take a lua_State argument, so that the
lack of a tmpnam() function can be reported using luaL_error(). The only place
that uses lua_tmpnam() is os_tmpname() in loslib.c, so the change was trivial.

My changes to lua_tmpnam() are:

#if defined(LUA_PS3)

#define LUA_TMPNAMBUFSIZE		32
#define lua_tmpnam(L,b,e)		((void)b,e=1, \
								luaL_error(L, LUA_QL("tmpnam") " not supported"))

#else

#define LUA_TMPNAMBUFSIZE		L_tmpnam
#define lua_tmpnam(L,b,e)		{ (void)L, e = (tmpnam(b) == NULL); }

#endif

Since os_tmpname() is just testing err for nonzero, setting e to 1 will trigger
its tmpnam()-failure code path.

This also has the advantage of homogenizing all of the lua_<something> macros,
now they all take a lua_State argument as the first argument.

I hope these modifications are useful for other lua users.

Thank you for developing this wonderful scripting language! We're currently
using it across three platforms (PC, Xbox 360, PS3) and porting it was a snap!

scott

-- 
J. Scott Hofmann                      http://cougar.kniggets.org
mailto:shofmann@mindspring.com