Use 'MRB_METHOD' macro

This commit is contained in:
Jonas Kulla 2013-09-03 10:48:20 +02:00
parent 8674cb8e06
commit 121df799ab
4 changed files with 91 additions and 82 deletions

View File

@ -156,9 +156,10 @@ findLastDot(char *str)
}
/* File class methods */
static mrb_value
fileBasename(mrb_state *mrb, mrb_value)
MRB_METHOD(fileBasename)
{
MRB_UNUSED_PARAM;
mrb_value filename;
const char *suffix = 0;
@ -185,9 +186,10 @@ fileBasename(mrb_state *mrb, mrb_value)
return str;
}
static mrb_value
fileDelete(mrb_state *mrb, mrb_value)
MRB_METHOD(fileDelete)
{
MRB_UNUSED_PARAM;
mrb_int argc;
mrb_value *argv;
@ -207,9 +209,10 @@ fileDelete(mrb_state *mrb, mrb_value)
return mrb_nil_value();
}
static mrb_value
fileDirname(mrb_state *mrb, mrb_value)
MRB_METHOD(fileDirname)
{
MRB_UNUSED_PARAM;
mrb_value filename;
mrb_get_args(mrb, "S", &filename);
@ -219,9 +222,10 @@ fileDirname(mrb_state *mrb, mrb_value)
return mrb_str_new_cstr(mrb, dir);
}
static mrb_value
fileExpandPath(mrb_state *mrb, mrb_value)
MRB_METHOD(fileExpandPath)
{
MRB_UNUSED_PARAM;
const char *path;
const char *defDir = 0;
@ -238,9 +242,10 @@ fileExpandPath(mrb_state *mrb, mrb_value)
return mrb_str_new_cstr(mrb, buffer);
}
static mrb_value
fileExtname(mrb_state *mrb, mrb_value)
MRB_METHOD(fileExtname)
{
MRB_UNUSED_PARAM;
mrb_value filename;
mrb_get_args(mrb, "S", &filename);
@ -249,9 +254,10 @@ fileExtname(mrb_state *mrb, mrb_value)
return mrb_str_new_cstr(mrb, ext);
}
static mrb_value
fileOpen(mrb_state *mrb, mrb_value)
MRB_METHOD(fileOpen)
{
MRB_UNUSED_PARAM;
mrb_value path;
const char *mode = "r";
mrb_value block = mrb_nil_value();
@ -288,9 +294,10 @@ fileOpen(mrb_state *mrb, mrb_value)
return obj;
}
static mrb_value
fileRename(mrb_state *mrb, mrb_value)
MRB_METHOD(fileRename)
{
MRB_UNUSED_PARAM;
const char *from, *to;
mrb_get_args(mrb, "zz", &from, &to);
@ -300,15 +307,15 @@ fileRename(mrb_state *mrb, mrb_value)
}
static mrb_value
mrbNoop(mrb_state *, mrb_value self)
MRB_METHOD(mrbNoop)
{
MRB_UNUSED_PARAM;
return self;
}
/* File instance methods */
static mrb_value
fileClose(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileClose)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p);
@ -337,8 +344,7 @@ readLine(FILE *f, QVector<char> &buffer)
}
}
static mrb_value
fileEachLine(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileEachLine)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p, FileImpl::Read);
@ -368,8 +374,7 @@ fileEachLine(mrb_state *mrb, mrb_value self)
return self;
}
static mrb_value
fileEachByte(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileEachByte)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p, FileImpl::Read);
@ -391,8 +396,7 @@ fileEachByte(mrb_state *mrb, mrb_value self)
return self;
}
static mrb_value
fileIsEof(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileIsEof)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p);
@ -404,8 +408,7 @@ fileIsEof(mrb_state *mrb, mrb_value self)
return mrb_bool_value(isEof);
}
static mrb_value
fileSetPos(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileSetPos)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p);
@ -419,8 +422,7 @@ fileSetPos(mrb_state *mrb, mrb_value self)
return self;
}
static mrb_value
fileGetPos(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileGetPos)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p);
@ -432,8 +434,7 @@ fileGetPos(mrb_state *mrb, mrb_value self)
return mrb_fixnum_value(pos);
}
static mrb_value
fileRead(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileRead)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p, FileImpl::Read);
@ -458,8 +459,7 @@ fileRead(mrb_state *mrb, mrb_value self)
// FIXME this function always splits on newline right now,
// to make rs fully work, I'll have to use some strrstr magic I guess
static mrb_value
fileReadLines(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileReadLines)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p, FileImpl::Read);
@ -497,8 +497,7 @@ fileReadLines(mrb_state *mrb, mrb_value self)
return ary;
}
static mrb_value
fileWrite(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileWrite)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p, FileImpl::Write);
@ -513,8 +512,7 @@ fileWrite(mrb_state *mrb, mrb_value self)
return mrb_fixnum_value(count);
}
static mrb_value
fileGetPath(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileGetPath)
{
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
checkValid(mrb, p);
@ -531,8 +529,7 @@ getFileStat(mrb_state *mrb, struct stat &fileStat)
stat(filename, &fileStat);
}
static mrb_value
fileGetMtime(mrb_state *mrb, mrb_value self)
MRB_METHOD(fileGetMtime)
{
mrb_value path = getProperty(mrb, self, CSpath);
@ -543,9 +540,10 @@ fileGetMtime(mrb_state *mrb, mrb_value self)
}
/* FileTest module functions */
static mrb_value
fileTestDoesExist(mrb_state *mrb, mrb_value)
MRB_METHOD(fileTestDoesExist)
{
MRB_UNUSED_PARAM;
const char *filename;
mrb_get_args(mrb, "z", &filename);
@ -554,27 +552,30 @@ fileTestDoesExist(mrb_state *mrb, mrb_value)
return mrb_bool_value(result == 0);
}
static mrb_value
fileTestIsFile(mrb_state *mrb, mrb_value)
MRB_METHOD(fileTestIsFile)
{
MRB_UNUSED_PARAM;
struct stat fileStat;
getFileStat(mrb, fileStat);
return mrb_bool_value(S_ISREG(fileStat.st_mode));
}
static mrb_value
fileTestIsDirectory(mrb_state *mrb, mrb_value)
MRB_METHOD(fileTestIsDirectory)
{
MRB_UNUSED_PARAM;
struct stat fileStat;
getFileStat(mrb, fileStat);
return mrb_bool_value(S_ISDIR(fileStat.st_mode));
}
static mrb_value
fileTestSize(mrb_state *mrb, mrb_value)
MRB_METHOD(fileTestSize)
{
MRB_UNUSED_PARAM;
struct stat fileStat;
getFileStat(mrb, fileStat);

View File

@ -39,9 +39,10 @@
void mrbBindingTerminate();
static mrb_value
kernelEval(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelEval)
{
MRB_UNUSED_PARAM;
const char *exp;
mrb_int expLen;
mrb_get_args(mrb, "s", &exp, &expLen);
@ -73,17 +74,19 @@ static void printP(mrb_state *mrb,
gState->eThread().showMessageBox(RSTRING_PTR(buffer), SDL_MESSAGEBOX_INFORMATION);
}
static mrb_value
kernelP(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelP)
{
MRB_UNUSED_PARAM;
printP(mrb, "inspect", "\n");
return mrb_nil_value();
}
static mrb_value
kernelPrint(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelPrint)
{
MRB_UNUSED_PARAM;
printP(mrb, "to_s", "");
return mrb_nil_value();
@ -105,9 +108,10 @@ srandCurrentTime(int *currentSeed)
srand(*currentSeed);
}
static mrb_value
kernelRand(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelRand)
{
MRB_UNUSED_PARAM;
if (!srandCalled)
{
srandCurrentTime(&currentSeed);
@ -138,9 +142,10 @@ kernelRand(mrb_state *mrb, mrb_value)
}
}
static mrb_value
kernelSrand(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelSrand)
{
MRB_UNUSED_PARAM;
srandCalled = true;
if (mrb->c->ci->argc == 1)
@ -163,17 +168,19 @@ kernelSrand(mrb_state *mrb, mrb_value)
}
}
static mrb_value
kernelExit(mrb_state *, mrb_value)
MRB_METHOD(kernelExit)
{
MRB_UNUSED_PARAM;
mrbBindingTerminate();
return mrb_nil_value();
}
static mrb_value
kernelLoadData(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelLoadData)
{
MRB_UNUSED_PARAM;
const char *filename;
mrb_get_args(mrb, "z", &filename);
@ -193,9 +200,10 @@ kernelLoadData(mrb_state *mrb, mrb_value)
return obj;
}
static mrb_value
kernelSaveData(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelSaveData)
{
MRB_UNUSED_PARAM;
mrb_value obj;
const char *filename;
@ -217,9 +225,10 @@ kernelSaveData(mrb_state *mrb, mrb_value)
return mrb_nil_value();
}
static mrb_value
kernelInteger(mrb_state *mrb, mrb_value)
MRB_METHOD(kernelInteger)
{
MRB_UNUSED_PARAM;
mrb_value obj;
mrb_get_args(mrb, "o", &obj);

View File

@ -882,9 +882,10 @@ verifyMarshalHeader(MarshalContext *ctx)
throw Exception(Exception::TypeError, "incompatible marshal file format (can't be read)");
}
static mrb_value
marshalDump(mrb_state *mrb, mrb_value)
MRB_METHOD(marshalDump)
{
MRB_UNUSED_PARAM;
mrb_value val;
mrb_value port = mrb_nil_value();
mrb_int limit = 100;
@ -944,9 +945,10 @@ marshalDump(mrb_state *mrb, mrb_value)
return ret;
}
static mrb_value
marshalLoad(mrb_state *mrb, mrb_value)
MRB_METHOD(marshalLoad)
{
MRB_UNUSED_PARAM;
mrb_value port;
mrb_get_args(mrb, "o", &port);

View File

@ -53,18 +53,20 @@ timeFromSecondsInt(mrb_state *mrb, time_t seconds)
return obj;
}
static mrb_value
timeAt(mrb_state *mrb, mrb_value)
MRB_METHOD(timeAt)
{
MRB_UNUSED_PARAM;
mrb_int seconds;
mrb_get_args(mrb, "i", &seconds);
return timeFromSecondsInt(mrb, seconds);
}
static mrb_value
timeNow(mrb_state *mrb, mrb_value)
MRB_METHOD(timeNow)
{
MRB_UNUSED_PARAM;
TimeImpl *p = new TimeImpl;
gettimeofday(&p->_tv, 0);
@ -87,8 +89,7 @@ secondsAdded(mrb_state *mrb, TimeImpl *p, mrb_int seconds)
return wrapObject(mrb, newP, TimeType);
}
static mrb_value
timePlus(mrb_state *mrb, mrb_value self)
MRB_METHOD(timePlus)
{
mrb_int seconds;
mrb_get_args(mrb, "i", &seconds);
@ -104,8 +105,7 @@ timePlus(mrb_state *mrb, mrb_value self)
return wrapObject(mrb, newP, TimeType);
}
static mrb_value
timeMinus(mrb_state *mrb, mrb_value self)
MRB_METHOD(timeMinus)
{
mrb_value minuent;
mrb_get_args(mrb, "o", &minuent);
@ -133,8 +133,7 @@ timeMinus(mrb_state *mrb, mrb_value self)
return mrb_nil_value();
}
static mrb_value
timeCompare(mrb_state *mrb, mrb_value self)
MRB_METHOD(timeCompare)
{
mrb_value cmpTo;
mrb_get_args(mrb, "o", &cmpTo);
@ -167,8 +166,7 @@ timeCompare(mrb_state *mrb, mrb_value self)
return mrb_fixnum_value(1);
}
static mrb_value
timeStrftime(mrb_state *mrb, mrb_value self)
MRB_METHOD(timeStrftime)
{
const char *format;
mrb_get_args(mrb, "z", &format);
@ -182,8 +180,7 @@ timeStrftime(mrb_state *mrb, mrb_value self)
}
#define TIME_ATTR(attr) \
static mrb_value \
timeGet_##attr(mrb_state *mrb, mrb_value self) \
MRB_METHOD(timeGet_##attr) \
{ \
TimeImpl *p = getPrivateData<TimeImpl>(mrb, self); \
return mrb_fixnum_value(p->_tm.tm_##attr); \