Browse Source

renamed do_file_baton and do_file_after for more generic use

v0.2.x
Brett Langdon 13 years ago
parent
commit
6a5c7615f2
1 changed files with 10 additions and 10 deletions
  1. +10
    -10
      src/luastate.cc

+ 10
- 10
src/luastate.cc View File

@ -5,27 +5,27 @@ using namespace v8;
uv_async_t async; uv_async_t async;
struct do_file_baton{
struct async_baton{
Persistent<Function> callback; Persistent<Function> callback;
char* file_name;
char* name;
bool error; bool error;
char msg[1000]; char msg[1000];
LuaState* state; LuaState* state;
}; };
void do_file(uv_work_t *req){ void do_file(uv_work_t *req){
do_file_baton* baton = static_cast<do_file_baton*>(req->data);
async_baton* baton = static_cast<async_baton*>(req->data);
if(luaL_dofile(baton->state->lua_, baton->file_name)){
if(luaL_dofile(baton->state->lua_, baton->name)){
baton->error = true; baton->error = true;
sprintf(baton->msg, "Exception In File %s Has Failed:\n%s\n", baton->file_name, lua_tostring(baton->state->lua_, -1));
sprintf(baton->msg, "Exception In File %s Has Failed:\n%s\n", baton->name, lua_tostring(baton->state->lua_, -1));
} }
} }
void do_file_after(uv_work_t *req){
void async_after(uv_work_t *req){
HandleScope scope; HandleScope scope;
do_file_baton* baton = (do_file_baton *)req->data;
async_baton* baton = (async_baton *)req->data;
Local<Value> argv[2]; Local<Value> argv[2];
const int argc = 2; const int argc = 2;
@ -145,15 +145,15 @@ Handle<Value> LuaState::DoFile(const Arguments& args){
} }
LuaState* obj = ObjectWrap::Unwrap<LuaState>(args.This()); LuaState* obj = ObjectWrap::Unwrap<LuaState>(args.This());
do_file_baton* baton = new do_file_baton();
baton->file_name = file_name;
async_baton* baton = new async_baton();
baton->name = file_name;
baton->callback = callback; baton->callback = callback;
baton->state = obj; baton->state = obj;
obj->Ref(); obj->Ref();
uv_work_t *req = new uv_work_t; uv_work_t *req = new uv_work_t;
req->data = baton; req->data = baton;
uv_queue_work(uv_default_loop(), req, do_file, do_file_after);
uv_queue_work(uv_default_loop(), req, do_file, async_after);
return scope.Close(Undefined()); return scope.Close(Undefined());
} }


Loading…
Cancel
Save