Exemplo n.º 1
0
	/*static*/
	bool Script::HasExtension(const char *script, const char *extension)
	{
		std::string scriptStr(script);
		std::string extStr(".");
		extStr += extension;
		
		return scriptStr.size() >= extStr.size() && scriptStr.substr(scriptStr.size()-extStr.size()) == extStr;
	}
Exemplo n.º 2
0
void SkAnimateBase::onEndElement(SkAnimateMaker& maker) {
    fChanged = false;
    setTarget(maker);
    if (field.size()) {
        SkASSERT(fTarget);
        fFieldInfo = fTarget->getMember(field.c_str());
        field.reset();
    }
    if (lval.size()) {
        // lval must be of the form x[y]
        const char* lvalStr = lval.c_str();
        const char* arrayEnd = strchr(lvalStr, '[');
        if (arrayEnd == NULL)
            return; //should this return an error?
        size_t arrayNameLen = arrayEnd - lvalStr;
        SkString arrayStr(lvalStr, arrayNameLen);
        SkASSERT(fTarget);  //this return an error?
        fFieldInfo = fTarget->getMember(arrayStr.c_str());
        SkString scriptStr(arrayEnd + 1, lval.size() - arrayNameLen - 2);
        SkAnimatorScript::EvaluateInt(maker, this, scriptStr.c_str(), &fFieldOffset);
    }
}
Exemplo n.º 3
0
//fname:path of the file
int NeoScript::ExecuteScriptFile(std::string fname)
{
	//get whole file string
	std::ifstream fin(fname);
	std::istreambuf_iterator<char> beg(fin), end;
	std::string scriptStr(beg, end);
	fin.close();
	//get lua runtime
	int top = lua_gettop(lua_S);
	int loaderr = luaL_loadbuffer(lua_S, scriptStr.data(), scriptStr.length(),
			fname.c_str());

	if (loaderr)
	{
		std::string errMsg = lua_tostring(lua_S, -1);
		lua_settop(lua_S, top);
#ifdef DEBUG
		std::cout << "Unable to execute Lua script file: '" << fname << "'\n\n"
				<< errMsg << "\n";
#endif
		return -1;
	}

	// call it
	if (lua_pcall(lua_S, 0, 0, 0))
	{
		std::string errMsg = lua_tostring(lua_S, -1);
		lua_settop(lua_S, top);
#ifdef DEBUG
		std::cout << "Unable to execute Lua script file: '" << fname << "'\n\n"
				<< errMsg << "\n";
#endif
		return -1;
	}

	lua_settop(lua_S, top); // just in case :P
	return 0;
}
Exemplo n.º 4
0
wxString wxLuaFreezeApp::LoadScript(const wxString& filename, bool only_check)
{
    // lots of debugging to make sure that everything is ok
    wxFile f;

    if (!f.Open(filename, wxFile::read))
    {
        OutputPrint(wxString::Format(wxT("Unable to open this executable file '%s' in read-only mode.\n"), filename.c_str()));
        return wxEmptyString;
    }

    // end of file is : "<wxLuaFreeze:%010d>", script_len
    #define END_TAG_LEN 24

    if (f.Seek(-END_TAG_LEN, wxFromEnd) == wxInvalidOffset)
    {
        f.Close();
        OutputPrint(wxString::Format(wxT("Unable to seek to last %d bytes at end of '%s'.\n"), END_TAG_LEN, filename.c_str()));
        return wxEmptyString;
    }

    // do some sanity checking before reading the script length

    char tag_buf[END_TAG_LEN+2] = {0};
    memset(tag_buf, 0, sizeof(char)*(END_TAG_LEN+2));
    long script_len = 0;

    if (f.Read((void*)tag_buf, END_TAG_LEN) == wxInvalidOffset)
    {
        f.Close();
        OutputPrint(wxString::Format(wxT("Unable to read wxLuaFreeze tag info at end of '%s'.\n"), filename.c_str()));
        return wxEmptyString;
    }

    if (sscanf(tag_buf, "<wxLuaFreeze:%ld>", &script_len) != 1)
    {
        f.Close();

        // they only wanted to know if the script exists, assume it's valid
        if (only_check)
            return LOADSCRIPT_MISSING;

        OutputPrint(wxString::Format(wxT("Expecting '<wxLuaFreeze:[script length]>' at end of '%s'.\n")
                                     wxT("Did you forget to run wxluafreeze.lua to attach your script?\n"), filename.c_str()));
        return wxEmptyString;
    }
    else if (f.Seek(-END_TAG_LEN - script_len, wxFromEnd) == wxInvalidOffset)
    {
        f.Close();
        OutputPrint(wxString::Format(wxT("Unable to seek to beginning of wxLua script at end of '%s'.\n"), filename.c_str()));
        return wxEmptyString;
    }

    // size should be valid from Seek statement
    char *script = (char*)malloc(script_len+2);
    if (script)
    {
        memset(script, 0, sizeof(script_len+2));
        f.Read(script, script_len);
        script[script_len] = 0;
    }

    f.Close();

    // we finally have our script!
    wxString scriptStr(lua2wx(script));
    free(script);

    return scriptStr;
}
Exemplo n.º 5
0
	/*static*/
 	std::string Script::GetExtension(const char *script)
	{
		std::string scriptStr(script);
		return scriptStr.substr(scriptStr.rfind("."));
	}