<commit_before>/*
 *  Copyright 2012 The lev Authors. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

 #include "lev_new_base.h"

#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <lua.h>
#include <lauxlib.h>
#include "luv_debug.h"

#ifndef WIN32
#include <ctype.h>
#include <unistd.h>
#include <sys/utsname.h>
#endif

/*

  X:TODO Beginning of PROCESS Module...
  
*/

#define UNWRAP(h) \
  process_obj* self = container_of((h), process_obj, handle); \
  lua_State* L = self->handle.loop->data;

typedef struct {
  LEVBASE_REF_FIELDS
} process_obj;

static int process_new(lua_State* L) {
  uv_loop_t* loop;
  process_obj* self;

  loop = uv_default_loop();
  assert(L == loop->data);

  self = (process_obj*)create_obj_init_ref(L, sizeof *self, "lev.process");

  return 1;
}

static int process_cwd(lua_State* L) {
  size_t size = 2*PATH_MAX-1;
  char path[2*PATH_MAX];
  uv_err_t err;

  err = uv_cwd(path, size);
  if (err.code != UV_OK) {
    return luaL_error(L, "uv_cwd: %s", uv_strerror(err));
  }
  lua_pushstring(L, path);
  return 1;
}

static luaL_reg methods[] = {
   /*{ "method_name",     ...      }*/
  { NULL,         NULL            }
};


static luaL_reg functions[] = {
   { "new", process_new }
  ,{ "cwd", process_cwd }
  ,{ NULL, NULL }<commit_msg>Implement process.pid(). Need to discuss whether we prefer functions or properties.<commit_after>/*
 *  Copyright 2012 The lev Authors. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

 #include "lev_new_base.h"

#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <lua.h>
#include <lauxlib.h>
#include "luv_debug.h"

#ifndef WIN32
#include <ctype.h>
#include <unistd.h>
#include <sys/utsname.h>
#endif

/*

  X:TODO Beginning of PROCESS Module...
  
*/

#define UNWRAP(h) \
  process_obj* self = container_of((h), process_obj, handle); \
  lua_State* L = self->handle.loop->data;

typedef struct {
  LEVBASE_REF_FIELDS
} process_obj;

static int process_new(lua_State* L) {
  uv_loop_t* loop;
  process_obj* self;

  loop = uv_default_loop();
  assert(L == loop->data);

  self = (process_obj*)create_obj_init_ref(L, sizeof *self, "lev.process");

  return 1;
}

static int process_cwd(lua_State* L) {
  size_t size = 2*PATH_MAX-1;
  char path[2*PATH_MAX];
  uv_err_t err;

  err = uv_cwd(path, size);
  if (err.code != UV_OK) {
    return luaL_error(L, "uv_cwd: %s", uv_strerror(err));
  }
  lua_pushstring(L, path);
  return 1;
}

static int process_pid(lua_State* L) {
  int pid = getpid();
  lua_pushinteger(L, pid);
  return 1;
}

static luaL_reg methods[] = {
   /*{ "method_name",     ...      }*/
  { NULL,         NULL            }
};


static luaL_reg functions[] = {
   { "new", process_new }
  ,{ "cwd", process_cwd }
  ,{ "pid", process_pid }
  ,{ NULL, NULL }
{'fraction_non_alphanumeric': 0.1296725960299046, 'fraction_numerical': 0.007991750451147204, 'mean_word_length': 3.454649827784156, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2320060', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1363, 'n_words': 401}