9492192b73
In preparation for switching to LuaJIT, which doesn't support PUC Lua's thing of using C++ exceptions for lua_error. Requires replacing all uses of lua_error (and things calling lua_error) with custom versions that throw an exception instead and adding an exception -> lua error wrapper at all C++ -> Lua boundaries.
49 lines
912 B
C
49 lines
912 B
C
/*
|
|
* fwrite.c
|
|
* Luabins Lua-less write API using FILE * as buffer
|
|
* See copyright notice in luabins.h
|
|
*/
|
|
|
|
#include "luaheaders.h"
|
|
|
|
#include "fwrite.h"
|
|
|
|
/* TODO: Note that stream errors are ignored. Handle them better? */
|
|
|
|
void lbs_fwriteTableHeader(
|
|
FILE * f,
|
|
int array_size,
|
|
int hash_size
|
|
)
|
|
{
|
|
fputc(LUABINS_CTABLE, f);
|
|
fwrite(
|
|
(const unsigned char *)&array_size,
|
|
LUABINS_LINT,
|
|
1,
|
|
f
|
|
);
|
|
fwrite(
|
|
(const unsigned char *)&hash_size,
|
|
LUABINS_LINT,
|
|
1,
|
|
f
|
|
);
|
|
}
|
|
|
|
void lbs_fwriteNumber(FILE * f, lua_Number value)
|
|
{
|
|
fputc(LUABINS_CNUMBER, f);
|
|
fwrite((const unsigned char *)&value, LUABINS_LNUMBER, 1, f);
|
|
}
|
|
|
|
void lbs_fwriteString(
|
|
FILE * f,
|
|
const char * value,
|
|
size_t length
|
|
)
|
|
{
|
|
fputc(LUABINS_CSTRING, f);
|
|
fwrite((const unsigned char *)&length, LUABINS_LSIZET, 1, f);
|
|
fwrite((const unsigned char *)value, length, 1, f);
|
|
}
|