Esempio n. 1
0
static void openwithtags() {
	int32 iotag = lua_newtag();
	int32 closedtag = lua_newtag();
	uint32 i;
	for (i = 0; i < sizeof(iolibtag) / sizeof(iolibtag[0]); i++) {
		// put both tags as upvalues for these functions
		lua_pushnumber(iotag);
		lua_pushnumber(closedtag);
		lua_pushCclosure(iolibtag[i].func, 2);
		lua_setglobal(iolibtag[i].name);
	}

	g_fin = new LuaFile();
	g_fin->_stdin = true;
	setfile(addfile(g_fin), FINPUT, iotag);

	g_fout = new LuaFile();
	g_fout->_stdout = true;
	setfile(addfile(g_fout), FOUTPUT, iotag);

	g_stdin = new LuaFile();
	g_stdin->_stdin = true;
	setfile(addfile(g_stdin), "_STDIN", iotag);

	g_stdout = new LuaFile();
	g_stdout->_stdout = true;
	setfile(addfile(g_stdout), "_STDOUT", iotag);

	g_stderr = new LuaFile();
	g_stderr->_stderr = true;
	setfile(addfile(g_stderr), "_STDERR", iotag);
}
Esempio n. 2
0
File: liolib.c Progetto: jeske/hz
static void openwithtags (void)
{
  int iotag = lua_newtag();
  int closedtag = lua_newtag();
  int i;
  for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
    /* put both tags as upvalues for these functions */
    lua_pushnumber(iotag);
    lua_pushnumber(closedtag);
    lua_pushCclosure(iolibtag[i].func, 2);
    lua_setglobal(iolibtag[i].name);
  }
  setfile(stdin, FINPUT, iotag);
  setfile(stdout, FOUTPUT, iotag);
  setfile(stdin, "_STDIN", iotag);
  setfile(stdout, "_STDOUT", iotag);
  setfile(stderr, "_STDERR", iotag);
}
Esempio n. 3
0
void LuaBase::registerLua() {
	// Register system table
	lua_Object system_table = lua_createtable();
	lua_pushobject(system_table);
	lua_setglobal("system");

	lua_pushobject(system_table);
	refSystemTable = lua_ref(1);

	for (unsigned i = 0; i < ARRAYSIZE(system_defaults); i++) {
		lua_pushobject(lua_getref(refSystemTable));
		lua_pushstring(system_defaults[i].name);
		lua_pushnumber(system_defaults[i].key);
		lua_settable();
	}

	// Create and populate system.controls table
	lua_Object controls_table = lua_createtable();
	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("controls");
	lua_pushobject(controls_table);
	lua_settable();

	for (int i = 0; controls[i].name; i++) {
		lua_pushobject(controls_table);
		lua_pushstring(controls[i].name);
		lua_pushnumber(controls[i].key);
		lua_settable();
	}

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("camChangeHandler");
	lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler));
	lua_settable();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("axisHandler");
	lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler));
	lua_settable();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("buttonHandler");
	lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler));
	lua_settable();

	lua_pushobject(lua_getglobal("type"));
	refTypeOverride = lua_ref(true);
	lua_pushCclosure(LUA_OPCODE(LuaBase, typeOverride), 0);
	lua_setglobal("type");

	// Register constants for box types
	lua_pushnumber(Sector::NoneType);
	lua_setglobal("NONE");
	lua_pushnumber(Sector::WalkType);
	lua_setglobal("WALK");
	lua_pushnumber(Sector::CameraType);
	lua_setglobal("CAMERA");
	lua_pushnumber(Sector::SpecialType);
	lua_setglobal("SPECIAL");
	lua_pushnumber(Sector::HotType);
	lua_setglobal("HOT");

	lua_pushobject(lua_setfallback("concat", LUA_OPCODE(LuaBase, concatFallback)));
	refOldConcatFallback = lua_ref(1);

	// initialize Text globals
	lua_pushstring("x");
	refTextObjectX = lua_ref(true);
	lua_pushstring("y");
	refTextObjectY = lua_ref(true);
	lua_pushstring("font");
	refTextObjectFont = lua_ref(true);
	lua_pushstring("width");
	refTextObjectWidth = lua_ref(true);
	lua_pushstring("height");
	refTextObjectHeight = lua_ref(true);
	lua_pushstring("fgcolor");
	refTextObjectFGColor = lua_ref(true);
	lua_pushstring("bgcolor");
	refTextObjectBGColor = lua_ref(true);
	lua_pushstring("fxcolor");
	refTextObjectFXColor = lua_ref(true);
	lua_pushstring("hicolor");
	refTextObjectHIColor = lua_ref(true);
	lua_pushstring("duration");
	refTextObjectDuration = lua_ref(true);
	lua_pushstring("center");
	refTextObjectCenter = lua_ref(true);
	lua_pushstring("ljustify");
	refTextObjectLJustify = lua_ref(true);
	lua_pushstring("rjustify");
	refTextObjectRJustify = lua_ref(true);
	lua_pushstring("volume");
	refTextObjectVolume = lua_ref(true);
	lua_pushstring("pan");
	refTextObjectPan = lua_ref(true);
	lua_pushstring("background");
	refTextObjectBackground = lua_ref(true);
}
Esempio n. 4
0
static void testC() {
#define getnum(s)	((*s++) - '0')
#define getname(s)	(nome[0] = *s++, nome)

	static int32 locks[10];
	lua_Object reg[10];
	char nome[2];
	char *s = luaL_check_string(1);
	nome[1] = 0;
	while (1) {
		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':
				{
					int32 n=getnum(s);
					reg[n] = lua_getglobal(getname(s));
					break;
				}
			case 'G':
				{
					int32 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':
				{
					int32 n = getnum(s);
					reg[n] = lua_getref(locks[getnum(s)]);
					break;
				}
			case 'u':
				lua_unref(locks[getnum(s)]);
				break;
			case 'p':
				{
					int32 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;
			default:
				luaL_verror("unknown command in `testC': %c", *(s - 1));
		}
		if (*s == 0)
			return;
		if (*s++ != ' ')
			lua_error("missing ` ' between commands in `testC'");
	}
}