コード例 #1
0
void Lua_V1::UnLockSet() {
	lua_Object nameObj = lua_getparam(1);
	if (!lua_isstring(nameObj))
		return;

	const char *name = lua_getstring(nameObj);
	// TODO implement proper unlocking
	g_grim->setSetLock(name, false);
}
コード例 #2
0
ファイル: profiler.c プロジェクト: alexsilva/lua_profiler
static void profile_show_text(lua_State *L) {
    check_start(L);
    // Spent runtime so far.
    float total_spent = calc_elapsed_time(PROFILE_START_TIME, clock());

    // Lua args
    lua_Object lobj = lua_getparam(L, 1);
    char *breakln = lua_isstring(L, lobj) ? lua_getstring(L, lobj) : "\n";

    lobj = lua_getparam(L, 2);
    char *offsetc = lua_isstring(L, lobj) ? lua_getstring(L, lobj) : "\t";

    Meta **array = get_metadata_array(L);

    render_text(L, array, STACK_INDEX - 1, offsetc, breakln);

    printf("TOTAL TIME SPENT: %.3f%s", total_spent, breakln);
}
コード例 #3
0
ファイル: lua_v1.cpp プロジェクト: gmacon/residual
void L1_CheckForFile() {
	lua_Object strObj = lua_getparam(1);

	if (!lua_isstring(strObj))
		return;

	const char *filename = lua_getstring(strObj);
	pushbool(g_resourceloader->getFileExists(filename));
}
コード例 #4
0
ファイル: lua_v2.cpp プロジェクト: Akz-/residual
void Lua_V2::FRUTEY_Begin() {
	lua_Object param1 = lua_getparam(1);

	if (!lua_isstring(param1))
		error("Lua_V2::FRUTEY_Begin - Unknown parameters");

	const char *paramText = lua_getstring(param1);
	error("Lua_V2::FRUTEY_Begin(%s) - TODO: Implement opcode", paramText);
}
コード例 #5
0
ファイル: lua_v1.cpp プロジェクト: gmacon/residual
// Scene functions
void L1_LockSet() {
	lua_Object nameObj = lua_getparam(1);
	if (!lua_isstring(nameObj))
		return;

	const char *name = lua_getstring(nameObj);
	// TODO implement proper locking
	g_grim->setSceneLock(name, true);
}
コード例 #6
0
ファイル: lua_v2_actor.cpp プロジェクト: olldray/residualvm
void Lua_V2::PlayActorChore() {
	lua_Object actorObj = lua_getparam(1);
	lua_Object choreObj = lua_getparam(2);
	lua_Object costumeObj = lua_getparam(3);
//	lua_Object modeObj = lua_getparam(4);
//	lua_Object paramObj = lua_getparam(5);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);

	if (!lua_isstring(choreObj) || !lua_isstring(costumeObj))
		lua_pushnil();

/*	bool mode = false;
	float param = 0.0;

	if (!lua_isnil(modeObj)) {
		if (lua_getnumber(modeObj) != 0.0)
			mode = true;
		if (!lua_isnil(paramObj))
			if (lua_isnumber(paramObj))
				param = lua_getnumber(paramObj);
	}*/

	const char *choreName = lua_getstring(choreObj);
	const char *costumeName = lua_getstring(costumeObj);
	Costume *costume = actor->findCostume(costumeName);

	if (costume == NULL) {
		actor->pushCostume(costumeName);
		costume = actor->findCostume(costumeName);
	}

	PoolChore *chore = (PoolChore *)costume->getChore(choreName);
	costume->playChore(choreName);
	if (chore) {
		lua_pushusertag(chore->getId(), MKTAG('C','H','O','R'));
	} else {
		lua_pushnil();
	}

}
コード例 #7
0
static void L2_LoadSound() {
	lua_Object strObj = lua_getparam(1);

	if (!lua_isstring(strObj))
		return;

	const char *str = lua_getstring(strObj);
	// FIXME: implement code
	warning("L2_LoadSound: stub, wants to load %s", str);
}
コード例 #8
0
ファイル: lua_v2_sound.cpp プロジェクト: frnknstn/residualvm
void Lua_V2::ImSetVoiceEffect() {
    // This only seems to be used in the demo.
    lua_Object strObj = lua_getparam(1);

    if (!lua_isstring(strObj))
        return;

    const char *str = lua_getstring(strObj);
    warning("Lua_V2::ImSetVoiceEffect: implement opcode, wants effect %s", str);
}
コード例 #9
0
ファイル: cdluactx.c プロジェクト: gcfavorites/tastools
/***************************************************************************\
* CD_METAFILE.                                                              *
\***************************************************************************/
static void *cdmetafile_checkdata(int param)
{
    lua_Object data;

    data = lua_getparam(param);
    if (!lua_isstring(data))
        lua_error("cdCreateCanvas CD_METAFILE: data should be of type string!");

    return lua_getstring(data);
}
コード例 #10
0
ファイル: WidgetLuaWrap.c プロジェクト: ekoeppen/kino-2
static void _wrap_ElementSetCSSProperty(void) {

    Element * _arg0;
    char * _arg1;
    char * _arg2;

{
  if (!lua_isnil (lua_getparam (1))) _arg0 = lua_getuserdata (lua_getparam (1));
  else _arg0 = NULL;
}
{
  _arg1 = lua_getstring (lua_getparam (2));
}
{
  _arg2 = lua_getstring (lua_getparam (3));
}
    ElementSetCSSProperty(_arg0,_arg1,_arg2);
    
}
コード例 #11
0
ファイル: lua_v2.cpp プロジェクト: olldray/residualvm
void Lua_V2::MakeCurrentSetup() {
	lua_Object setupObj = lua_getparam(1);
	if (lua_isnumber(setupObj)) {
		int num = (int)lua_getnumber(setupObj);
		g_grim->makeCurrentSetup(num);
	} else if (lua_isstring(setupObj)) {
		const char *setupName = lua_getstring(setupObj);
		error("Lua_V2::MakeCurrentSetup: Not implemented case: setup: %s", setupName);
	}
}
コード例 #12
0
ファイル: lbuiltin.cpp プロジェクト: agharbi/residual
static const char *to_string(lua_Object obj) {
	char *buff = luaL_openspace(30);
	TObject *o = luaA_Address(obj);
	switch (ttype(o)) {
	case LUA_T_NUMBER:
	case LUA_T_STRING:
		return lua_getstring(obj);
	case LUA_T_ARRAY:
		{
			sprintf(buff, "table: %p", (void *)o->value.a);
			return buff;
		}
	case LUA_T_CLOSURE:
		{
			sprintf(buff, "function: %p", (void *)o->value.cl);
			return buff;
		}
	case LUA_T_PROTO:
		{
			sprintf(buff, "function: %p", (void *)o->value.tf);
			return buff;
		}
	case LUA_T_CPROTO:
		{
			// WORKAROUND: C++ forbids casting from a pointer-to-function to a
			// pointer-to-object. We use a union to work around that.
			union {
				void *objPtr;
				lua_CFunction funcPtr;
			} ptrUnion;

			ptrUnion.funcPtr = o->value.f;

			sprintf(buff, "function: %p", ptrUnion.objPtr);
			return buff;
		}
	case LUA_T_USERDATA:
		{
			sprintf(buff, "userdata: %d", o->value.ud.id);
			return buff;
		}
	case LUA_T_TASK:
		{
			sprintf(buff, "task: %d", (int)o->value.n);
			return buff;
		}
	case LUA_T_NIL:
		return "nil";
	default:
#ifdef LUA_DEBUG
		LUA_INTERNALERROR("internal error");
#endif
		return NULL;
	}
}
コード例 #13
0
ファイル: lua.cpp プロジェクト: giucam/residual
void LuaBase::setTextObjectParams(TextObjectCommon *textObject, lua_Object tableObj) {
	lua_Object keyObj;

	lua_pushobject(tableObj);
	lua_pushobject(lua_getref(refTextObjectX));
	keyObj = lua_gettable();
	if (keyObj) {
		if (lua_isnumber(keyObj)) {
			float num = lua_getnumber(keyObj);
			if (g_grim->getGameType() == GType_MONKEY4)
				textObject->setX((int)(num * 320));
			else
				textObject->setX((int)num);
		}
	}

	lua_pushobject(tableObj);
	lua_pushobject(lua_getref(refTextObjectY));
	keyObj = lua_gettable();
	if (keyObj) {
		if (lua_isnumber(keyObj)) {
			float num = lua_getnumber(keyObj);
			if (g_grim->getGameType() == GType_MONKEY4)
				textObject->setY((int)(num * 240));
			else
				textObject->setY((int)num);
		}
	}

	lua_pushobject(tableObj);
	lua_pushobject(lua_getref(refTextObjectFont));
	keyObj = lua_gettable();
	if (keyObj) {
		if (g_grim->getGameType() == GType_MONKEY4 && lua_isstring(keyObj)) {
			const char *str = lua_getstring(keyObj);
			Font *font = 0;
			foreach (Font *f, Font::getPool()) {
				if (f->getFilename() == str) {
					font = f;
				}
			}
			if (!font) {
				font = g_resourceloader->loadFont(str);
			}

			textObject->setFont(font);
		} else if (lua_isuserdata(keyObj) && lua_tag(keyObj) == MKTAG('F','O','N','T')) {
			textObject->setFont(getfont(keyObj));
		} else if (g_grim->getGameType() == GType_MONKEY4 && !textObject->getFont() && g_grim->getGamePlatform() == Common::kPlatformPS2) {
			// HACK:
			warning("HACK: No default font set for PS2-version, just picking one for now");
			textObject->setFont(*Font::getPool().begin());
		}
	}
コード例 #14
0
/* python object presentation */
static char *get_pyobject_repr(lua_State *L, PyObject *pyobject) {
    char *repr = "...";
    PyObject *str = PyObject_Str(pyobject);
    if (str && py_convert(L, str)) {
        lua_Object lstr = lua_pop(L);
        if (lua_isstring(L, lstr)) {
            repr = lua_getstring(L, lstr);
        }
    }
    return repr;
}
コード例 #15
0
ファイル: lua_v1.cpp プロジェクト: gmacon/residual
void L1_Save() {
	lua_Object fileName = lua_getparam(1);
	if (lua_isnil(fileName)) {
		g_grim->saveGame("");
	} else if (lua_isstring(fileName)) {
		g_grim->saveGame(lua_getstring(fileName));
	} else {
		warning("Save() fileName is wrong");
		return;
	}
}
コード例 #16
0
ファイル: lua_v2.cpp プロジェクト: olldray/residualvm
void Lua_V2::LockBackground() {
	lua_Object filenameObj = lua_getparam(1);

	if (!lua_isstring(filenameObj)) {
		lua_pushnil();
		return;
	}
	const char *filename = lua_getstring(filenameObj);
	warning("Lua_V2::LockBackground, filename: %s", filename);
	// FIXME: implement missing rest part of code
}
コード例 #17
0
ファイル: lua_v2.cpp プロジェクト: Akz-/residual
void Lua_V2::SetResidualVMPreference()  {
	lua_Object keyObj = lua_getparam(1);
	lua_Object valueObj = lua_getparam(2);

	if (lua_isstring(keyObj) && lua_isnumber(valueObj)) {
		const Common::String key = lua_getstring(keyObj);
		float value = lua_getnumber(valueObj);

		g_emiregistry->Set(key, value);
	}
}
コード例 #18
0
ファイル: lua_v1.cpp プロジェクト: gmacon/residual
void L1_TurnLightOn() {
	lua_Object lightObj = lua_getparam(1);

	Scene *scene = g_grim->getCurrScene();
	bool isOn = getbool(2);
	if (lua_isnumber(lightObj)) {
		scene->setLightEnabled((int)lua_getnumber(lightObj), isOn);
	} else if (lua_isstring(lightObj)) {
		scene->setLightEnabled(lua_getstring(lightObj), isOn);
	}
}
コード例 #19
0
ファイル: lua_v1.cpp プロジェクト: Harrypoppins/grim_mouse
void Lua_V1::WriteRegistryValue() {
	lua_Object keyObj = lua_getparam(1);
	lua_Object valObj = lua_getparam(2);

	if (!lua_isstring(keyObj))
		return;

	const char *key = lua_getstring(keyObj);
	if (strcmp(key, "GrimMannyState") == 0) //This isn't used. it's probably a left over from testing phase.
		return;

	// Check isnumber first, because isstring returns true for numbers
	if (lua_isnumber(valObj)) {
		int val = (int)lua_getnumber(valObj);
		g_registry->setInt(key, val);
	} else if (lua_isstring(valObj)) {
		const char *val = lua_getstring(valObj);
		g_registry->setString(key, val);
	}
}
コード例 #20
0
void Lua_V1::Load() {
	lua_Object fileName = lua_getparam(1);
	if (lua_isnil(fileName)) {
		g_grim->loadGame("");
	} else if (lua_isstring(fileName)) {
		g_grim->loadGame(lua_getstring(fileName));
	} else {
		warning("Load() fileName is wrong");
		return;
	}
}
コード例 #21
0
ファイル: lstrlib.cpp プロジェクト: Botje/residualvm-tools
static void add_s (lua_Object newp, struct Capture *cap)
{
  if (lua_isstring(newp)) {
    const char *news = lua_getstring(newp);
    int32 l = lua_strlen(newp);
    int32 i;
    for (i=0; i<l; i++) {
      if (news[i] != ESC)
        luaL_addchar(news[i]);
      else {
        i++;  /* skip ESC */
        if (!isdigit((byte)news[i]))
          luaL_addchar(news[i]);
        else {
          int32 level = check_cap(news[i], cap);
          addnchar(cap->capture[level].init, cap->capture[level].len);
        }
      }
    }
  }
  else {  /* is a function */
    lua_Object res;
    int32 status;
    int32 oldbuff;
    lua_beginblock();
    push_captures(cap);
    /* function may use buffer, so save it and create a new one */
    oldbuff = luaL_newbuffer(0);
    status = lua_callfunction(newp);
    /* restore old buffer */
    luaL_oldbuffer(oldbuff);
    if (status != 0) {
      lua_endblock();
      lua_error(NULL);
    }
    res = lua_getresult(1);
    if (lua_isstring(res))
      addnchar(lua_getstring(res), lua_strlen(res));
    lua_endblock();
  }
}
コード例 #22
0
static void L2_UnLockBackground() {
	lua_Object filenameObj = lua_getparam(1);

	if (!lua_isstring(filenameObj)) {
		lua_pushnil();
		return;
	}

	const char *filename = lua_getstring(filenameObj);
	// FIXME: implement missin code
	warning("L2_UnLockBackground: stub, filename: %s", filename);
}
コード例 #23
0
ファイル: lua_v2.cpp プロジェクト: olldray/residualvm
void Lua_V2::LoadBundle() {
	lua_Object paramObj = lua_getparam(1);
	if (lua_isstring(paramObj) || lua_isnil(paramObj)) {
		const char *name = lua_getstring(paramObj);
		// FIXME: implement missing function
/*		if (!func(name))
			lua_pushnil();
		else*/
			lua_pushnumber(1.0);
		warning("Lua_V2::LoadBundle: stub, name: %s", name);
	}
}
コード例 #24
0
ファイル: iolib.c プロジェクト: Akagi201/learning-lua
/*
** To get a environment variables
*/
static void io_getenv (void)
{
 lua_Object s = lua_getparam(1);
 if (!lua_isstring(s))
  lua_pushnil();
 else
 {
  char *env = getenv(lua_getstring(s));
  if (env == NULL) lua_pushnil();
  else             lua_pushstring(env); 
 }
}
コード例 #25
0
ファイル: lua_v1.cpp プロジェクト: gmacon/residual
void L1_PrintWarning() {
	if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) {
		Common::String msg("Warning: ");
		lua_Object strObj = lua_getparam(1);
		if (lua_isnil(strObj))
			msg += "(nil)";
		if (!lua_isstring(strObj))
			return;
		msg += Common::String(lua_getstring(strObj)) + "\n";
		printf("%s", msg.c_str());
	}
}
コード例 #26
0
void Lua_V1::MakeCurrentSet() {
	lua_Object nameObj = lua_getparam(1);
	if (!lua_isstring(nameObj)) {
		// TODO setting current set null
		warning("Lua_V1::MakeCurrentSet: implement missing case");
		return;
	}

	const char *name = lua_getstring(nameObj);
	Debug::debug(Debug::Engine, "Entered new scene '%s'.", name);
	g_grim->setSet(name);
}
コード例 #27
0
ファイル: iolib.c プロジェクト: iSCInc/lua
/*
** Write a variable. On error put 0 on stack, otherwise put 1.
** LUA interface:
**			status = write (variable [,format])
**
** O formato pode ter um dos seguintes especificadores:
**
**	s ou S -> para string
**	f ou F, g ou G, e ou E -> para reais
**	i ou I -> para inteiros
**
**	Estes especificadores podem vir seguidos de:
**
**		[?][m][.n]
**
**	onde:
**		? -> indica justificacao
**			< = esquerda
**			| = centro
**			> = direita (default)
**		m -> numero maximo de campos (se exceder estoura)
**		n -> indica precisao para
**			reais -> numero de casas decimais
**			inteiros -> numero minimo de digitos
**			string -> nao se aplica
*/
static char *buildformat (char *e, lua_Object o)
{
 static char buffer[512];
 static char f[80];
 char *string = &buffer[255];
 char t, j='r';
 int  m=0, n=0, l;
 while (isspace(*e)) e++;
 t = *e++;
 if (*e == '<' || *e == '|' || *e == '>') j = *e++;
 while (isdigit(*e))
  m = m*10 + (*e++ - '0');
 e++;	/* skip point */
 while (isdigit(*e))
  n = n*10 + (*e++ - '0');

 sprintf(f,"%%");
 if (j == '<' || j == '|') sprintf(strchr(f,0),"-");
 if (m != 0)   sprintf(strchr(f,0),"%d", m);
 if (n != 0)   sprintf(strchr(f,0),".%d", n);
 sprintf(strchr(f,0), "%c", t);
 switch (tolower(t))
 {
  case 'i': t = 'i';
   sprintf (string, f, (long int)lua_getnumber(o));
  break;
  case 'f': case 'g': case 'e': t = 'f';
   sprintf (string, f, (float)lua_getnumber(o));
  break;
  case 's': t = 's';
   sprintf (string, f, lua_getstring(o));
  break;
  default: return "";
 }
 l = strlen(string);
 if (m!=0 && l>m)
 {
  int i;
  for (i=0; i<m; i++)
   string[i] = '*';
  string[i] = 0;
 }
 else if (m!=0 && j=='|')
 {
  int i=l-1;
  while (isspace(string[i])) i--;
  string -= (m-i) / 2;
  i=0;
  while (string[i]==0) string[i++] = ' ';
  string[l] = 0;
 }
 return string;
}
コード例 #28
0
ファイル: iolib.c プロジェクト: iSCInc/lua
/*
** Open a file to write appended.
** LUA interface:
**			status = appendto (filename)
** where:
**			status = 2 -> success (already exist)
**			status = 1 -> success (new file)
**			status = 0 -> error
*/
static void io_appendto (void)
{
 lua_Object o = lua_getparam (1);
 if (o == NULL)			/* restore standart output */
 {
  if (out != stdout)
  {
   fclose (out);
   out = stdout;
  }
  lua_pushnumber (1);
 }
 else
 {
  if (!lua_isstring (o))
  {
   lua_error ("incorrect argument to function 'appendto`");
   lua_pushnumber (0);
  }
  else
  {
   int r;
   FILE *fp;
   struct stat st;
   if (stat(lua_getstring(o), &st) == -1) r = 1;
   else                                   r = 2;
   fp = fopen (lua_getstring(o),"a");
   if (fp == NULL)
   {
    lua_pushnumber (0);
   }
   else
   {
    if (out != stdout) fclose (out);
    out = fp;
    lua_pushnumber (r);
   }
  }
 }
}
コード例 #29
0
ファイル: lbuiltin.c プロジェクト: Akagi201/learning-lua
static void testC (void) {
#define getnum(s)	((*s++) - '0')
#define getname(s)	(nome[0] = *s++, nome)

  static int locks[10];
  lua_Object reg[10];
  char nome[2];
  char *s = luaL_check_string(1);
  nome[1] = 0;
  for (;;) {
    switch (*s++) {
      case '0': case '1': case '2': case '3': case '4':
      case '5': case '6': case '7': case '8': case '9':
        lua_pushnumber(*(s-1) - '0');
        break;

      case 'c': reg[getnum(s)] = lua_createtable(); break;
      case 'C': { lua_CFunction f = lua_getcfunction(lua_getglobal(getname(s)));
                  lua_pushcclosure(f, getnum(s));
                  break;
                }
      case 'P': reg[getnum(s)] = lua_pop(); break;
      case 'g': { int n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; }
      case 'G': { int n = getnum(s);
                  reg[n] = lua_rawgetglobal(getname(s));
                  break;
                }
      case 'l': locks[getnum(s)] = lua_ref(1); break;
      case 'L': locks[getnum(s)] = lua_ref(0); break;
      case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
      case 'u': lua_unref(locks[getnum(s)]); break;
      case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
      case '=': lua_setglobal(getname(s)); break;
      case 's': lua_pushstring(getname(s)); break;
      case 'o': lua_pushobject(reg[getnum(s)]); break;
      case 'f': lua_call(getname(s)); break;
      case 'i': reg[getnum(s)] = lua_gettable(); break;
      case 'I': reg[getnum(s)] = lua_rawgettable(); break;
      case 't': lua_settable(); break;
      case 'T': lua_rawsettable(); break;
      case 'N' : lua_pushstring(lua_nextvar(lua_getstring(reg[getnum(s)])));
                 break;
      case 'n' : { int n=getnum(s);
                   n=lua_next(reg[n], (int)lua_getnumber(reg[getnum(s)]));
                   lua_pushnumber(n); break;
                 }
      default: luaL_verror("unknown command in `testC': %c", *(s-1));
    }
  if (*s == 0) return;
  if (*s++ != ' ') lua_error("missing ` ' between commands in `testC'");
  }
}
コード例 #30
0
ファイル: lua_v1.cpp プロジェクト: gmacon/residual
void L1_MakeCurrentSet() {
	lua_Object nameObj = lua_getparam(1);
	if (!lua_isstring(nameObj)) {
		// TODO setting current set null
		warning("L1_MakeCurrentSet: implement missing case");
		return;
	}

	const char *name = lua_getstring(nameObj);
	if (gDebugLevel == DEBUG_NORMAL || gDebugLevel == DEBUG_ALL)
		printf("Entered new scene '%s'.\n", name);
	g_grim->setScene(name);
}