Ejemplo n.º 1
0
LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
  lua_lock(L);
  setfltvalue(L->top, n);
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 2
0
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
  lua_lock(L);
  setivalue(L->top, n);
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 3
0
LUA_API void lua_pushvalue (lua_State *L, int idx) {
  lua_lock(L);
  setobj2s(L, L->top, index2addr(L, idx));
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 4
0
LUA_API void lua_pushnil (lua_State *L) {
  lua_lock(L);
  setnilvalue(L->top);
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 5
0
Archivo: lapi.c Proyecto: AlexMax/d2k
LUA_API void lua_pushboolean (lua_State *L, int b) {
  lua_lock(L);
  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 6
0
Archivo: lapi.c Proyecto: AlexMax/d2k
LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
  lua_lock(L);
  setpvalue(L->top, p);
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 7
0
LUA_API void luaclr_setbytecodeenabled (lua_State *L, int value) {
  lua_lock(L);
  lua_assert(value == 0 || value == 1);
  G(L)->readbytecode = value;
  lua_unlock(L);
}
Ejemplo n.º 8
0
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
  lua_lock(L);
  setnvalue(L->top, cast_num(n));
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 9
0
static void DumpBlock(const void* b, size_t size, DumpState* D)
{
 lua_unlock(D->L);
 (*D->write)(D->L,b,size,D->data);
 lua_lock(D->L);
}
Ejemplo n.º 10
0
static int pmain(lua_State* L) {
  struct Smain* s = (struct Smain*)lua_touserdata(L, 1);
  int argc=s->argc;
  char** argv=s->argv;
  Proto* f;
  int scripts=0;
  int i;
  if (!lua_checkstack(L,argc)) fatal("too many input files");
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);
  /* compile each script from command line into a Lua function. */
  for (i=0; i<argc; i++) {
    const char* filename=IS("-") ? NULL : argv[i];
    if(IS("-L")) break;
    if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));
    scripts++;
  }
  /* compile each preload library from the command line into a Lua function. */
  for (i=0; i<preloads; i++) {
    char* filename=preload_libs[i];
    char* p;
    /* try loading library as if it is a normal file. */
    if (luaL_loadfile(L,filename)!=0) {
      /* try pre-loading library with 'require' module loading system. */
      lua_getglobal(L, "require");
      lua_pushstring(L, filename);
      lua_pushboolean(L, 1);
      lua_call(L, 2, 1);
      if (lua_iscfunction(L, -1)) { /* make sure it is not a C-Function. */
        lua_pop(L, 1);
        lua_pushfstring(L, "\nCan't preload C module: '%s'\n", filename);
        lua_concat(L, 2);  /* accumulate with error from luaL_findfile */
        fatal(lua_tostring(L,-1));
      }
      if (!lua_isfunction(L, -1)) { /* did we get an error? */
        lua_pushliteral(L, "\n");
        lua_concat(L, 3);  /* accumulate with error from luaL_findfile */
        fatal(lua_tostring(L,-1));
      } else {
        lua_remove(L, -2); /* remove error from luaL_findfile. */
      }
    } else {
      /* convert filename into package name. */
      p= filename + strlen(filename);
      for(;p >= filename; p--) {
        if(p[0] == '.') { /* Remove file extension. */
          p[0] = '\0';
          continue;
        }
        if(p[0] == '/') { /* Remove file path. */
          preload_libs[i] = p+1;
          break;
        }
      }
    }
  }
  /* generate a new Lua function to combine all of the compiled scripts. */
  f=combine(L, scripts);
  if (listing) luaU_print(f,listing>1);
  if (c_code && !parse_only) {
    FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
    if (D==NULL) cannot("open");
    lua_lock(L);
    slua_dumper_dump(D, output, L, f, stripping);
    lua_unlock(L);
    if (ferror(D)) cannot("write");
    if (fclose(D)) cannot("close");
  }
  if (dumping && !parse_only) {
    FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
    if (D==NULL) cannot("open");
    lua_lock(L);
    luaU_dump(L,f,writer,D,stripping);
    lua_unlock(L);
    if (ferror(D)) cannot("write");
    if (fclose(D)) cannot("close");
  }
  return 0;
}
Ejemplo n.º 11
0
int main(int argc, char* argv[]) {
	lua_State* L;
	const char *destfile, *destnum, *srcfile, *srcnum;
	Proto *fdestroot, *fsrcroot, *fparent, *fdest, *fsrc;
	int cdest, csrc;
	char *realdestnum = NULL, *realsrcnum = NULL;
	FILE* D;
	int diff, i;

	gargc = argc;
	gargv = argv;
	i = doargs(argc,argv);
	argc -= i;
	argv += i;

	if (printfuncnum && argc < 1) {
		usage("need 1 arguments for -pn at least", NULL);
	}
	if (argc < 4) {
		usage("need 4 arguments at least", NULL);
	}

	L = lua_open();
	glstate = L;
	luaB_opentests(L);

	destfile = argv[0];
	destnum = argv[1];
	if (luaL_loadfile(L, destfile) != 0) {
		fatal(lua_tostring(L, -1));
	}
	fdestroot = toproto(L, -1);

	if (printfuncnum) {
		printf("%d\n",0);
		printFuncStructure(fdestroot, "  0_");
		lua_close(L);
		return EXIT_SUCCESS;
	}

	realdestnum = (char*)calloc(strlen(destnum)+1, sizeof(char));
	fparent = findParentFunction(fdestroot, destnum, &cdest, realdestnum);
	if (cdest < 0) {
		if (realdestnum) { free(realdestnum); realdestnum = NULL; }
		fatal("cannot find dest function");
	}
	if (fparent == NULL) {
		fdest = fdestroot;
	} else {
		fdest = fparent->p[cdest];
	}

	srcfile = argv[2];
	srcnum = argv[3];
	if (luaL_loadfile(L, srcfile) != 0) {
		fatal(lua_tostring(L, -1));
	}
	fsrcroot = toproto(L, -1);
	realsrcnum = (char*)calloc(strlen(srcnum)+1, sizeof(char));
	fsrc = findParentFunction(fsrcroot, srcnum, &csrc, realsrcnum);
	if (csrc < 0) {
		if (realdestnum) { free(realdestnum); realdestnum = NULL; }
		if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; }
		fatal("cannot find src function");
	}
	if (fsrc == NULL) {
		fsrc = fsrcroot;
	} else {
		fsrc = fsrc->p[csrc];
	}

	if (!replace_sub){
		if (fparent == NULL) {
			if (realdestnum) { free(realdestnum); realdestnum = NULL; }
			if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; }
			fatal("cannot use root as dest function");
		}
		fprintf(stderr, "Replacing %s %s with %s %s ...\n", destfile, realdestnum, srcfile, realsrcnum);
		diff = replaceFunction(fparent, cdest, fsrc);
		fprintf(stderr, "1 function replaced ok.\n");
	} else {
		fprintf(stderr, "Replacing sub functions of %s %s with those of %s %s ...\n", destfile, realdestnum, srcfile, realsrcnum);
		diff = replaceSubFunctions(fdest, fsrc);
		fprintf(stderr, "%d function replaced ok.", MIN(fdest->sizep, fsrc->sizep));
		if (fdest->sizep != fsrc->sizep) {
			fprintf(stderr, " The dest has %d sub functions, but the src has %d . Please have a check.\n", fdest->sizep, fsrc->sizep);
		} else {
			fprintf(stderr, "\n");
		}
	}

	if (realdestnum) { free(realdestnum); realdestnum = NULL; }
	if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; }

	if (strict == 1 && diff > 0){
		fatal("strip mode on and incompatible functions found, stop writing output.");
	}

	D = (output == NULL) ? stdout : fopen(output, "wb");
	if (D == NULL) cannot("open");
	lua_lock(L);
	luaU_dump(L, fdestroot, writer, D, 0);
	lua_unlock(L);
	if (ferror(D)) cannot("write");
	if (fclose(D)) cannot("close");

	printf("%s generated!\n", output);

	lua_close(L);
	return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
LUA_API void lua_pushlwstring (lua_State *L, const lua_WChar *s, size_t len) {
  lua_lock(L);
  setwsvalue(L, L->top, luaS_newlwstr(L, s, len));
  api_incr_top(L);
  lua_unlock(L);
}
Ejemplo n.º 13
0
LUA_API void lua_pushlclosure (lua_State *L, LClosure *c) {
  lua_lock(L);
  setclLvalue(L, L->top, c);
  api_incr_top(L);
  lua_unlock(L);
}