예제 #1
0
BOOL CALLBACK luaX_resenm(HMODULE hm, LPCTSTR ty, LPTSTR nm, LONG_PTR lp)
{
	lua_State* L = (lua_State*)lp;
	lua_checkstack(L, 2);
	HRSRC hRes = FindResource(hm, nm, luaX_host<ILuaLib>(L,0)->m_rt);
	HGLOBAL hResL;
	char* buf;
	size_t size = 0;
	hResL = LoadResource(hm, hRes);
	buf = (char*)LockResource(hResL);
	size = (size_t)SizeofResource(hm, hRes);
	if (size > 80) size = 80;
	if ((size > 4) && (buf[0] == '-') && (buf[1] == '-'))
	{
		for (size_t i = 2; (i < size); i++) if (buf[i] == '\n') size = i;
	}
	else
	{
		size = 0;
	}
	luaX_pushstring(L, CString(nm));
	if (size > 0)
		lua_pushlstring(L, buf + 2, size - 2);
	else
		lua_pushboolean(L, TRUE);
	lua_settable(L, -3);
	return TRUE;
}
예제 #2
0
int get_class(lua_State* L, const char* name) {
	lua_getglobal(L, "package");
	if (lua_istable(L, -1)) {
		lua_getfield(L, -1, "loaded");
		lua_remove(L, -2);
		int c = 0;
		while (lua_istable(L, -1)) {
			luaX_pushstring(L, pop_name(name, c++));
			lua_gettable(L, -2);
			lua_remove(L, -2);
		}
	}
	if (!lua_isfunction(L, -1)) return luaL_error(L,"Class not found: %s",name);
	return 1;
};
예제 #3
0
//R1 (Number) Time zone offset in hours including DST applicable at the time and date.
//R2 (String) Name of the time zone.
//R3 (Number) DST offset in hours applicable at the time or date.
int LuaTimeZone(lua_State* L)
{
	luaC_checkmethod(L, 3);
	timeud* p1 = (timeud*)lua_touserdata(L, 1);
	if (!(p1->typ < tud_abs_hour)) return luaL_argerror(L, 1, "Only applies to an absolute Time with at least minute resolution.");
	TIME_ZONE_INFORMATION tz;
	GetTimeZoneInformation(&tz);

	SYSTEMTIME st;
	TimeSplit(p1->val, &st);
	DOUBLE loc = TimeMake(&st, 0.0) * (24 * 60);
	int ofs = (int)((p1->val * (24 * 60)) - loc);

	lua_pushnumber(L, (double)ofs / 60.0);
	luaX_pushstring(L, (ofs == tz.Bias)? CString(tz.StandardName) : CString(tz.DaylightName));
	lua_pushnumber(L, (double)((ofs == tz.Bias)? tz.StandardBias : tz.DaylightBias) / 60.0);
	return 3;
}
예제 #4
0
LUALIB_API int luaX_loadresource(lua_State* L, LPCTSTR resname)
{
	if (luaX_host<ILuaLib>(L,0)->m_rt.GetLength() < 1) return 0;
	lua_checkstack(L, 2);
	HRSRC hRes;
	HMODULE hM = _Module.GetResourceInstance();
	CString name(resname);
	hRes = FindResource(hM, name, luaX_host<ILuaLib>(L,0)->m_rt);
	if (hRes == NULL)
	{
		luaX_pushstring(L, CString("\tno resource '") + name + CString("'"));
		return LUA_ERRFILE;
	}
	name = CString("=Resource-") + name;
	size_t sz = name.GetLength() + 1;
	char* nm = new char[sz];
	wcstombs_s(NULL, nm, sz, name, sz);
	int r = lua_load(L, LuaX_ResReader, (void*)&hRes, nm, NULL);
	delete nm;
	return r;
}
예제 #5
0
LUALIB_API int luaX_loadfile (lua_State *L, LPCTSTR fn, LPCTSTR fp)
{
	lua_checkstack(L, 2);
	CString cn(fn);
	CString ep(fp);
	int p = cn.Find(ep);
	if (p >= 0) cn = CString("\\") + cn.Mid(p + ep.GetLength());
	cn = CString('@') + cn;
	int sz = cn.GetLength();
	int bs = WideCharToMultiByte(CP_THREAD_ACP, 0, cn, sz + 1, NULL, 0, NULL, NULL);
	char* chunkname = new char[bs];
	int rs = WideCharToMultiByte(CP_THREAD_ACP, 0, cn, sz + 1, chunkname, bs, NULL, NULL);
	LuaX_LoadF lf;
	int r = 0;
	if (_wfopen_s(&lf.f, fn, TEXT("r")) != 0) r = LUA_ERRFILE;
	if (r != 0)
		luaX_pushstring(L, CString("Cannot open script file: ") + fn);
	else
		r = lua_load(L, LuaX_FileReader, &lf, chunkname, NULL);
	delete chunkname;
	if (lf.f != NULL) fclose(lf.f);
	return r;
}