コード例 #1
0
ファイル: unistd.c プロジェクト: batrick/luaposix
/***
Create a link.
@function link
@string target name
@string link name
@bool[opt=false] soft link
@treturn[1] int `0`, if successful
@return[2] nil
@treturn[2] string error message
@treturn[2] int errnum
@see link(2)
@see symlink(2)
*/
static int
Plink(lua_State *L)
{
	const char *oldpath = luaL_checkstring(L, 1);
	const char *newpath = luaL_checkstring(L, 2);
	int symbolicp = optboolean(L, 3, 0);
	checknargs(L, 3);
	return pushresult(L, (symbolicp ? symlink : link)(oldpath, newpath), NULL);
}
コード例 #2
0
ファイル: lua_compress.c プロジェクト: RKelson93/mushclient
static int myencodebase64 (lua_State *L)
  {
  // get text to hash
  size_t textLength;
  const UC * text = luaL_checklstring (L, 1, &textLength);
  int bMultiLine = optboolean (L, 2, 0);

	size_t i;
	size_t j=0;
	int bytes;
  int bufsize;
  char * result = NULL;

  // result will be 4/3 size of original  
  // plus padding for final couple of bytes

  bufsize = ((textLength / 3) * 4) + 4;

  if (bMultiLine)
     bufsize += (((textLength / WRAP_POINT) + 1) * 2);  // (allow 2 bytes for cr/lfs)

  result = malloc (bufsize);

  if (!result)
    luaL_error (L, "not enough memory for encoding");

	// go thru converting each 3 bytes into 4 base64 bytes
  if (textLength >= 3)
    {
    for (i=0; i < (textLength - 2); i+=3)
      {
		  bytes = (text [i] << 16)
		 	      + (text [i+1] << 8)
			      + (text [i+2]);
		  result[j++] = base64code[(bytes >> 18)  & 0x3F];
		  result[j++] = base64code[(bytes >> 12)  & 0x3F];
		  result[j++] = base64code[(bytes >> 6)   & 0x3F];
		  result[j++] = base64code[(bytes)        & 0x3F];

    // Add linefeeds every WRAP_POINT characters

		  if(bMultiLine && ((i % WRAP_POINT) == (WRAP_POINT - 3)))
        {                 
			  result[j++]='\r';
			  result[j++]='\n';
        }
	    }
    }
  else
コード例 #3
0
ファイル: mesh.c プロジェクト: stetre/moonassimp
static int AllIndices(lua_State *L)
    {
    mesh_t *mesh = checkmesh(L, 1);
    int zero_based = optboolean(L, 2, 0);
    unsigned int i;

    lua_newtable(L);
    if(mesh->mFaces == NULL || mesh->mNumFaces == 0)
        return 1;
    for(i = 0; i < mesh->mNumFaces; i++)
        {
        pushfaceindices(L, &(mesh->mFaces[i]), zero_based);
        lua_rawseti(L, -2, i+1);
        }
    return 1;
    }
コード例 #4
0
ファイル: skynet_main.c プロジェクト: gailufeng/skynet
int
main(int argc, char *argv[]) {
	const char * config_file = "config";
	if (argc > 1) {
		config_file = argv[1];
	}
	skynet_env_init();

	struct skynet_config config;

	struct lua_State *L = luaL_newstate();
	luaL_openlibs(L);	// link lua lib
	lua_close(L);

	L = luaL_newstate();

	int err = luaL_dofile(L, config_file);
	if (err) {
		fprintf(stderr,"%s\n",lua_tostring(L,-1));
		lua_close(L);
		return 1;
	} 
	_init_env(L);

	const char *path = optstring("lua_path","./lualib/?.lua;./lualib/?/init.lua");
	setenv("LUA_PATH",path,1);
	const char *cpath = optstring("lua_cpath","./lualib/?.so");
	setenv("LUA_CPATH",cpath,1);
	optstring("luaservice","./service/?.lua");

	config.thread =  optint("thread",8);
	config.mqueue_size = optint("mqueue",256);
	config.module_path = optstring("cpath","./service/?.so");
	config.logger = optstring("logger",NULL);
	config.harbor = optint("harbor", 1);
	config.master = optstring("master","tcp://127.0.0.1:2012");
	config.start = optstring("start","main.lua");
	config.local = optstring("address","tcp://127.0.0.1:2525");
	config.standalone = optboolean("standalone",0);

	lua_close(L);

	skynet_start(&config);

	return 0;
}