Example #1
0
static void SetClassDefaultAttribute(void)
{
  IupSetClassDefaultAttribute(luaL_check_string(1), luaL_check_string(2), luaL_opt_string(3,NULL));
}
Example #2
0
static int io_rename (lua_State *L) {
  return pushresult(L, rename(luaL_check_string(L, 1),
                    luaL_check_string(L, 2)) == 0);
}
Example #3
0
static int errorfb (lua_State *L) {
  int level = 1;  /* skip level 0 (it's this function) */
  int firstpart = 1;  /* still before eventual `...' */
  lua_Debug ar;
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  luaL_addstring(&b, "error: ");
  luaL_addstring(&b, luaL_check_string(L, 1));
  luaL_addstring(&b, "\n");
  while (lua_getstack(L, level++, &ar)) {
    char buff[120];  /* enough to fit following `sprintf's */
    if (level == 2)
      luaL_addstring(&b, "stack traceback:\n");
    else if (level > LEVELS1 && firstpart) {
      /* no more than `LEVELS2' more levels? */
      if (!lua_getstack(L, level+LEVELS2, &ar))
        level--;  /* keep going */
      else {
        luaL_addstring(&b, "       ...\n");  /* too many levels */
        while (lua_getstack(L, level+LEVELS2, &ar))  /* find last levels */
          level++;
      }
      firstpart = 0;
      continue;
    }
    sprintf(buff, "%4d:  ", level-1);
    luaL_addstring(&b, buff);
    lua_getinfo(L, "Snl", &ar);
    switch (*ar.namewhat) {
      case 'g':  case 'l':  /* global, local */
        sprintf(buff, "function `%.50s'", ar.name);
        break;
      case 'f':  /* field */
        sprintf(buff, "method `%.50s'", ar.name);
        break;
      case 't':  /* tag method */
        sprintf(buff, "`%.50s' tag method", ar.name);
        break;
      default: {
        if (*ar.what == 'm')  /* main? */
          sprintf(buff, "main of %.70s", ar.short_src);
        else if (*ar.what == 'C')  /* C function? */
          sprintf(buff, "%.70s", ar.short_src);
        else
          sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src);
        ar.source = NULL;  /* do not print source again */
      }
    }
    luaL_addstring(&b, buff);
    if (ar.currentline > 0) {
      sprintf(buff, " at line %d", ar.currentline);
      luaL_addstring(&b, buff);
    }
    if (ar.source) {
      sprintf(buff, " [%.70s]", ar.short_src);
      luaL_addstring(&b, buff);
    }
    luaL_addstring(&b, "\n");
  }
  luaL_pushresult(&b);
  lua_getglobal(L, LUA_ALERT);
  if (lua_isfunction(L, -1)) {  /* avoid loop if _ALERT is not defined */
    lua_pushvalue(L, -2);  /* error message */
    lua_rawcall(L, 1, 0);
  }
  return 0;
}
Example #4
0
/*
** If your system does not support `stderr', redefine this function, or
** redefine _ERRORMESSAGE so that it won't need _ALERT.
*/
static int luaB__ALERT (lua_State *L) {
  fputs(luaL_check_string(L, 1), stderr);
  return 0;
}
Example #5
0
void L1_new_dofile() {
	const char *fname_str = luaL_check_string(1);
	if (g_grim->bundle_dofile(fname_str) == 0)
		if (luaA_passresults() == 0)
			lua_pushuserdata(0);
}
Example #6
0
static void gettagmethod (void)
{
  lua_pushobject(lua_gettagmethod((int32)luaL_check_number(1),
                                  luaL_check_string(2)));
}
Example #7
0
static int luaB_setglobal (lua_State *L) {
  luaL_checkany(L, 2);
  lua_setglobal(L, luaL_check_string(L, 1));
  return 0;
}
Example #8
0
static int rmdir_lua(lua_State* L)
{
	const char* dir = luaL_check_string(L, 1);
	io_rmdir(".", dir);
	return 0;
}
Example #9
0
/*
** Return the string length
*/
static void str_len (void)
{
 lua_pushnumber(strlen(luaL_check_string(1)));
}
Example #10
0
static void luaB_gettagmethod (void) {
  lua_pushobject(lua_gettagmethod(luaL_check_int(1), luaL_check_string(2)));
}
Example #11
0
/*
** If your system does not support "stderr", redefine this function, or
** redefine _ERRORMESSAGE so that it won't need _ALERT.
*/
static void luaB_alert (void) {
  fputs(luaL_check_string(1), stderr);
}
Example #12
0
static void luaB_settagmethod (void) {
  lua_Object nf = luaL_nonnullarg(3);
  lua_pushobject(nf);
  lua_pushobject(lua_settagmethod(luaL_check_int(1), luaL_check_string(2)));
}
Example #13
0
static void Help(void)
{
  IupHelp(luaL_check_string(1));
}
Example #14
0
static void SetGlobal(void)
{
  IupStoreGlobal(luaL_check_string(1), luaL_check_string(2));
}
Example #15
0
static void PlotInsertStr(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPlotInsertStr(ih, luaL_check_int(2), luaL_check_int(3), luaL_check_string(4), (float)luaL_check_number(5));
}
Example #16
0
const char *luaL_opt_string(int32 numArg, const char *def) {
	return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : luaL_check_string(numArg);
}
Example #17
0
static void getglobal (void)
{
  lua_pushobject(lua_getglobal(luaL_check_string(1)));
}
Example #18
0
File: liolib.c Project: jeske/hz
static void io_execute (void)
{
  lua_pushnumber(system(luaL_check_string(1)));
}
Example #19
0
static void GetParam(void)
{
  getparam_data gp;
  lua_Object func;
  const char* title = luaL_check_string(1);
  void* user_data = (void*)&gp;
  const char* format = luaL_check_string(3);
  int param_count, param_extra, i, size, ret,
      line_size = 0, lua_param_start = 4;
  const char* f = format;
  const char* s;
  void* param_data[50];
  char param_type[50];

  gp.has_func = 0;
  gp.func_ref = 0;

  memset(param_data, 0, sizeof(void*)*50);
  memset(param_type, 0, sizeof(char)*50);

  param_count = iupGetParamCount(format, &param_extra);

  for (i = 0; i < param_count; i++)
  {
    char t = iupGetParamType(f, &line_size);

    if (t == 't') /* if separator */
    {
      f += line_size;
      i--; /* compensate next increment */
      continue;
    }

    switch(t)
    {
    case 'b':
    case 'i':
    case 'l':
      param_data[i] = malloc(sizeof(int));
      *(int*)(param_data[i]) = (int)luaL_check_number(lua_param_start); lua_param_start++;
      break;
    case 'a':
    case 'r':
      param_data[i] = malloc(sizeof(float));
      *(float*)(param_data[i]) = (float)luaL_check_number(lua_param_start); lua_param_start++;
      break;
    case 'f':
    case 'c':
    case 's':
    case 'm':
      s = luaL_check_string(lua_param_start); lua_param_start++;
      size = strlen(s);
      if (size < 512)
        param_data[i] = malloc(512);
      else
        param_data[i] = malloc(2*size);
      memcpy(param_data[i], s, size+1);
      break;
    }

    param_type[i] = t;
    f += line_size;
  }

  func = lua_getparam(2);
  if (lua_isfunction(func))
  {
    lua_pushobject(func);
    gp.func_ref = lua_ref(1);
    gp.has_func = 1;
  }

  ret = IupGetParamv(title, param_action, user_data, format, param_count, param_extra, param_data);

  lua_pushnumber(ret);

  if (ret)
  {
    for (i = 0; i < param_count; i++)
    {
      switch(param_type[i])
      {
      case 'b':
      case 'i':
      case 'l':
        lua_pushnumber(*(int*)(param_data[i]));
        break;
      case 'a':
      case 'r':
        lua_pushnumber(*(float*)(param_data[i]));
        break;
      case 'f':
      case 'c':
      case 's':
      case 'm':
        lua_pushstring((char*)(param_data[i]));
        break;
      }
    }
  }

  for (i = 0; i < param_count; i++)
  {
    free(param_data[i]);
  }

  if (gp.has_func)
    lua_unref(gp.func_ref);
}
Example #20
0
File: liolib.c Project: jeske/hz
static void io_remove  (void)
{
  pushresult(remove(luaL_check_string(1)) == 0);
}
Example #21
0
static int luaB_getglobal (lua_State *L) {
  lua_getglobal(L, luaL_check_string(L, 1));
  return 1;
}
Example #22
0
File: liolib.c Project: jeske/hz
static void io_rename (void)
{
  pushresult(rename(luaL_check_string(1),
                    luaL_check_string(2)) == 0);
}
Example #23
0
static int str_format (lua_State *L) {
    int arg = 1;
    const char *strfrmt = luaL_check_string(L, arg);
    luaL_Buffer b;
    luaL_buffinit(L, &b);
    while (*strfrmt) {
        if (*strfrmt != '%')
            luaL_putchar(&b, *strfrmt++);
        else if (*++strfrmt == '%')
            luaL_putchar(&b, *strfrmt++);  /* %% */
        else { /* format item */
            struct Capture cap;
            char form[MAX_FORMAT];  /* to store the format ('%...') */
            char buff[MAX_ITEM];  /* to store the formatted item */
            const char *initf = strfrmt;
            form[0] = '%';
            if (isdigit((unsigned char)*initf) && *(initf+1) == '$') {
                arg = *initf - '0';
                initf += 2;  /* skip the 'n$' */
            }
            arg++;
            cap.src_end = strfrmt+strlen(strfrmt)+1;
            cap.level = 0;
            strfrmt = match(L, initf, "[-+ #0]*(%d*)%.?(%d*)", &cap);
            if (cap.capture[0].len > 2 || cap.capture[1].len > 2 ||  /* < 100? */
                    strfrmt-initf > MAX_FORMAT-2)
                lua_error(L, "invalid format (width or precision too long)");
            strncpy(form+1, initf, strfrmt-initf+1); /* +1 to include conversion */
            form[strfrmt-initf+2] = 0;
            switch (*strfrmt++) {
            case 'c':
            case 'd':
            case 'i':
                sprintf(buff, form, luaL_check_int(L, arg));
                break;
            case 'o':
            case 'u':
            case 'x':
            case 'X':
                sprintf(buff, form, (unsigned int)luaL_check_number(L, arg));
                break;
            case 'e':
            case 'E':
            case 'f':
            case 'g':
            case 'G':
                sprintf(buff, form, luaL_check_number(L, arg));
                break;
            case 'q':
                luaI_addquoted(L, &b, arg);
                continue;  /* skip the "addsize" at the end */
            case 's': {
                size_t l;
                const char *s = luaL_check_lstr(L, arg, &l);
                if (cap.capture[1].len == 0 && l >= 100) {
                    /* no precision and string is too long to be formatted;
                       keep original string */
                    lua_pushvalue(L, arg);
                    luaL_addvalue(&b);
                    continue;  /* skip the "addsize" at the end */
                }
                else {
                    sprintf(buff, form, s);
                    break;
                }
            }
            default:  /* also treat cases 'pnLlh' */
                lua_error(L, "invalid option in `format'");
            }
            luaL_addlstring(&b, buff, strlen(buff));
        }
    }
    luaL_pushresult(&b);
    return 1;
}
Example #24
0
File: liolib.c Project: jeske/hz
static void io_getenv (void)
{
  lua_pushstring(getenv(luaL_check_string(1)));  /* if NULL push nil */
}
Example #25
0
static int io_execute (lua_State *L) {
  lua_pushnumber(L, system(luaL_check_string(L, 1)));
  return 1;
}
Example #26
0
void Lua_V1::ImSetVoiceEffect() {
	const char *effectName;

	effectName = luaL_check_string(1);
	Debug::warning(Debug::Imuse, "ImSetVoiceEffect(%s) Voice effects are not yet supported", effectName);
}
Example #27
0
static int io_getenv (lua_State *L) {
  lua_pushstring(L, getenv(luaL_check_string(L, 1)));  /* if NULL push nil */
  return 1;
}
Example #28
0
static void PlotAddStr(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPlotAddStr(ih, luaL_check_string(2), (float)luaL_check_number(3));
}
Example #29
0
static void rawgetglobal() {
	lua_pushobject(lua_rawgetglobal(luaL_check_string(1)));
}
Example #30
0
static void Message(void)
{
  IupMessage(luaL_check_string(1), luaL_check_string(2));
}