ivaneeo's blog

自由的力量,自由的生活。

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

#

功能描述:在Flex中嵌套框架,并且进行数值传递
1、编辑Flex框架组件iFrame.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
    resize="callLater(moveIFrame)"
    move="callLater(moveIFrame)">
    <mx:Script>
    <![CDATA[
        import flash.external.ExternalInterface;
        import flash.geom.Point;
        import flash.net.navigateToURL;
        private var __source: String;
        /**
         * Move iframe through ExternalInterface. The location is determined using localToGlobal()
         * on a Point in the Canvas.
         **/
        private function moveIFrame(): void
        {
            var localPt:Point = new Point(0, 0);
            var globalPt:Point = this.localToGlobal(localPt);
            ExternalInterface.call("moveIFrame", globalPt.x, globalPt.y, this.width, this.height);
        }
        /**
         * The source URL for the IFrame. When set, the URL is loaded through ExternalInterface.
         **/
        public function set source(source: String): void
        {
            if (source)
            {
                if (! ExternalInterface.available)
                {
                    throw new Error("ExternalInterface is not available in this container. Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required.");
                }
                __source = source;
                ExternalInterface.call("loadIFrame", source);
                moveIFrame();
            }
        }
        public function get source(): String
        {
            return __source;
        }
        /**
         * Whether the IFrame is visible.
         **/
        override public function set visible(visible: Boolean): void
        {
            super.visible=visible;
            if (visible)
            {
                ExternalInterface.call("showIFrame");
            }
            else
            {
                ExternalInterface.call("hideIFrame");
            }
        }
    ]]>
    </mx:Script>
</mx:Canvas>
2、放置到要使用框架的Flex中index.mxml,并写入引用哪个frame.html
<ui:IFrame id="iFrame" source="frame.html" visible="true" width="100%" height="300"/>
3、在引用框架的Flex生成页index.html里加入:
     <1. wmode set to opaque
     在调用swf的后面加上"wmode","opaque"
     例如:"pluginspage", "http://www.adobe.com/go/getflashplayer",
           "wmode","opaque"
     <2. the moveIFrame,hideIFrame,showIFrame,loadIFrame methods
     <script language="JavaScript" type="text/javascript">

<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 28;
// -----------------------------------------------------------------------------
// -->
function moveIFrame(x,y,w,h) {
    var frameRef=document.getElementById("myFrame");
    frameRef.style.left=x;
    frameRef.style.top=y;
    var iFrameRef=document.getElementById("myIFrame");
      iFrameRef.width=w;
      iFrameRef.height=h;
}
function hideIFrame(){
    document.getElementById("myFrame").style.visibility="hidden";
}

function showIFrame(){
    document.getElementById("myFrame").style.visibility="visible";
}
function loadIFrame(url){
      document.getElementById("myFrame").innerHTML = "<iframe id='myIFrame' src='" + url + "'frameborder='0'></iframe>";
}
//要调用的内容,加载前三个就可以了,后面这个函数是用来调用返回值
function getEditorText(){
      return document.getElementById("myIFrame").contentWindow.GetEditorText1();
}
</script>
     <3. the 'myFrame' div
         在</body>这前写入:
         <div id="myFrame" style="position:absolute;background-color:transparent;border:0         px;visibility:hidden;"></div>
4、在Flex页面index.mxml输入的函数值,调用index.html中的'getEditorText'函数,并且写入到text1.text中
     text1.text=ExternalInterface.call('getEditorText',param1,param2,param3,...)
     getEditorText:函数名称
     param:参数值
5、在生成页中取得框架中的函数
     框架内的frame.html,放置在head之间:
    function GetEditorText1(){
     return getHTML(params);
     index.html生成页的调用,设置在head之间:
     function getEditorText(){
      return document.getElementById("myIFrame").contentWindow.GetEditorText1();
     }
    
后记:实际中在这里只是调用一个层放在对应位置而已,当我们在Flex中做申缩动作时,层也要跟着改变,我是如此处理的:
     设置move或show事件,当move或show时则调用:iFrame.source = "frame.html"
参考:

具体的一个例子——使用IFrame这个框架的一个页面的代码如下:

<!-- saved from url=(0014)about:internet -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="AC_OETags.js" language="javascript"></script>
<style>
body { margin: 0px; overflow:hidden }
</style>


<script>
<!--
function moveIFrame(x,y,w,h) {
// alert("move to " + x + "," + y + ", " + w + "/" + h);
    var frameRef=document.getElementById("myFrame");
    frameRef.style.left=x;
   frameRef.style.top=y;
    frameRef.width=w;
    frameRef.height=h;
}

function hideIFrame(){
// alert("hide");
    document.getElementById("myFrame").style.visibility="hidden";
}

function showIFrame(){
// alert("show");
    document.getElementById("myFrame").style.visibility="visible";
}

function navigateTo(url) {
// alert("nav to " + url);
// alert("from " + document.getElementById("myFrame").location);
document.getElementById("myFrame").src = url;
}

-->
</script>


<script language="VBScript">
<!--

// Catch FS Commands in IE, and pass them to the corresponding JavaScript function.
Sub flexapp_FSCommand(ByVal command, ByVal str)
    call flexapp_DoFSCommand(command, str)
end sub

// -->
</script>
</head>
<body style="margin:0px">

<object onMouseDown="document.body.focus();"
   classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
  

codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,14

,0'
   width='100%' height='100%'
   id='flexapp' name='flexapp'>
   <param name='flashvars' value=''>
   <param name='src' value='EXPIframe.swf'>
   <param name="wmode" value="opaque">
   <embed pluginspage='http://www.macromedia.com/go/getflashplayer' width='100%'

height='100%'
       flashvars=''
       src='EXPIframe.swf'
       name='flexapp'
       wmode="opaque"
       swLiveConnect="true"
   />
</object>

<iframe id="myFrame" name="myFrame"
    frameborder="0"
    style="position:absolute;background-

color:transparent;border:0px;visibility:hidden;"></iframe>

</body>
</html>

posted @ 2012-03-08 22:48 ivaneeo 阅读(2526) | 评论 (1)编辑 收藏

浏览-选择文件-点击 “上传 ”后,效果如下:

弹出透明UI遮罩层 并显示上传这个过程 我这里设置太透明了 效果不是很立体

曾祥展

文件结构如图:

曾祥展

 

说明:用到“高山来客”的大文件上传组件 http://www.cnblogs.com/bashan/archive/2008/05/23/1206095.html

以及Newtonsoft.Json.dll Json字符串反序列化为对象 http://james.newtonking.com/projects/json-net.aspx

jquery.blockUI.js 弹出透明遮罩层 http://malsup.com/jquery/block/

jquery.form.js   表单验证Ajax提交 

参照了“蚂蚁飞了”的文章 多谢多谢 http://blog.csdn.net/jetsteven

 

 

HTML:

<form id="uploadForm" runat="server" enctype="multipart/form-data">   <div id="uploadfield"  style="width:600px; height:500px">    <input id="File1" type="file" runat="server" />    <asp:Button ID="Button1" runat="server"  Text="上传" onclick="Button1_Click" />     <p>文件上传进度条</p>     <p>文件上传进度条</p>     <p>文件上传进度条</p>     <p>文件上传进度条</p>     <p>文件上传进度条</p>     <p>文件上传进度条</p>      <p>文件上传进度条</p>    </div>                    <div id="ui"  style="display:none"  >      <div id="output" > </div>        <div id="progressbar"class="ui-progressbar ui-widget ui-widget-content ui-corner-all" style="width:296px; height:20px;"></div>    <input id="btn_cancel" type="button" value="取消上传" />   </div> </form>
 
js:
 
var inte; $(function() { $('#uploadForm').submit(function() {     return false; });  $('#uploadForm').ajaxForm({ //这里调用jquery.form.js表单注册方法     beforeSubmit: function(a, f, o) {//提交前的处理         o.dataType = "json";         $('#uploadfield').block({ message: $('#ui'), css: { width: '300px', border: '#b9dcfe 1px solid',padding: '0.5em 0.2em'  }         });         inte = self.setInterval("getprogress()", 500);     } });  $('#btn_cancel').click(function() {     var uploadid = $("#UploadID").val();     $.ajax({         type: "POST",         dataType: "json",         async: false, //ajax的请求时同步 只有一个线程         url: "upload_ajax.ashx",         data: "UploadID=" + uploadid + "&cancel=true",         success: function(obj) {             $("#output").html(obj.msg);             inte = self.clearInterval(inte);             $('#uploadfield').unblock();                            }     }); }); });  function getprogress() { var uploadid = $("#UploadID").val() $.ajax({     type: "POST",     dataType: "json",     async: false,     url: "upload_ajax.ashx",     data: "UploadID=" + uploadid,     success: function(obj) {     var p = obj.msg.Readedlength / obj.msg.TotalLength * 100;     var info = "<FONT color=Green> 当前上传文件:</FONT>" + obj.msg.CurrentFile;     info += "<br><FONT color=Green>" + obj.msg.FormatStatus + ":</FONT>" + obj.msg.Status;     info += "<br><FONT color=Green>文件大小:</FONT>" + obj.msg.TotalLength;     info += "<br><FONT color=Green>速度:</FONT>" + obj.msg.FormatRatio;     info += "<br><FONT color=Green>剩余时间:</FONT>" + obj.msg.LeftTime;       $("#output").html(info);     $("#progressbar").progressbar({ value: 0 }); //初始化     $("#progressbar").progressbar("option", "value", p);     $("#progressbar div").html(p.toFixed(2) + "%");     $("#progressbar div").addClass("percentText");     if (obj.msg.Status == 4) {         inte = self.clearInterval(inte);         $('#uploadfield').unblock();      }            } }); }
 
交互过程代码:
 
<%@ WebHandler Language="C#" Class="progressbar" %>  using System; using System.Web;  using BigFileUpload;//大文件引用命名空间 using Newtonsoft.Json;//对象到JSON的相互转换 using System.Text.RegularExpressions;//正则  public class progressbar : IHttpHandler {      private string template = "{{statue:'{0}',msg:{1}}}";    public void ProcessRequest(HttpContext context)    {        context.Response.ContentType = "text/plain";        try       {        string guid = context.Request["UploadID"];        string cancel =context.Request["cancel"];     UploadContext c = UploadContextFactory.GetUploadContext(guid);       if (!string.IsNullOrEmpty(cancel))     {                    c.Abort=true;                    throw new Exception("用户取消");        }        string json = Newtonsoft.Json.JsonConvert.SerializeObject(c);                    WriteResultJson(1, json, context,template);                 }catch (Exception err)        {            WriteResultJson(0, err.Message, context);        }    }      public static void WriteResultJson(int resultno, string description, HttpContext context) {     WriteResultJson(resultno, description, context, "{{statue:'{0}',msg:'{1}'}}"); }  public static void WriteResultJson(int resultno, string description, HttpContext context, string template) {     description = ClearBR(ReplaceString(description, "'", "|", false));     context.Response.Write(string.Format(template, resultno, description)); }  public static string ClearBR(string str) {     Regex r = null;     Match m = null;     r = new Regex(@"(\r|\n)", RegexOptions.IgnoreCase);     for (m = r.Match(str); m.Success; m = m.NextMatch())     {         str = str.Replace(m.Groups[0].ToString(), @"\n");     }     return str; }  public static string ReplaceString(string SourceString, string SearchString, string ReplaceString, bool IsCaseInsensetive) {     return Regex.Replace(SourceString, Regex.Escape(SearchString), ReplaceString, IsCaseInsensetive ? RegexOptions.IgnoreCase : RegexOptions.None); }    public bool IsReusable    {        get       {         return false;        }    }  }         
http://www.cnblogs.com/jcomet/archive/2010/03/24/1693467.html
posted @ 2012-02-29 20:42 ivaneeo 阅读(572) | 评论 (0)编辑 收藏

原理简单的不能再简单,就是替换变量,用转义字符替换你的字符串,把整个js变成一个字符串,然后随便加密替换,最后用eval来解释他。最后把整个js文件压缩下,没有注释,没有换行,没有空格,一般人都会看到吐血。

说了半天不够爽,总不能让大家手动加密和替换吧,以下是我的御用在线加密工具,jQuery就是用其中一个加密和压缩的:

http://www.javascriptobfuscator.com/Default.aspx

http://dean.edwards.name/packer/

这2网站只提供加密,不提供解密,其实你解密了看得人也很痛苦,没有注释,没有格式,全是abcd这样无意义的变量,真有心想学你js的人,那就让他学吧。你如果真的变态,那你不妨两边混合加密几次,保准没人看得懂,不过估计浏览器解释起来也挺费劲的。

特别友情提醒:meebe.net

1.加密后记着留住你原本的js文件,不要到时候改bug都改不了了。

2.加密后如果出现运行不了,请把你加密前的文件每次函数结束都加上";",因为去除换行后,浏览器解释器没碰到";"有时候会报错。如果加密后有错,请务必多加几个";"在每个语句结束或者定义结束的时候。


转自 meebe.net

posted @ 2012-02-28 22:41 ivaneeo 阅读(563) | 评论 (0)编辑 收藏

Step 1 – Install Visual Studio 2008

  1. If you don’t have it, get the express edition here: http://www.microsoft.com/Express/VC/
  2. Run through the installer, not much else to do.

Step 2 – Install wxWidgets

  1. Download wxWidgets (select the wxMSW installer file) from here:
    http://www.wxwidgets.org/downloads/
  2. I choose to install to c:\dev\wxwidgets\wxWidgets-2.8.10 but you can choose a different path if you want.

Step 3 – Create an environment variable for the wxWidgets path.

  1. Click the Start icon.
  2. Right click on Computer and choose Properties.
  3. Click Advanced system settings.
  4. Click the Environment variables button.
  5. Under System Variables, click New.
  6. Enter the Variable name: WXWIN
  7. Enter the Variable Value: C:\Dev\wxWidgets-2.8.10
  8. Click OK, click OK, click OK (yes three times).

Step 4 – Compile the wxWidgets Libraries.

  1. Browse to the following folder: C:\Dev\wxWidgets-2.8.10\build\msw
  2. Located the file called wx.dsw and open it with Visual Studio. (I just double-clicked on it.)
  3. Choose “Yes to all” when Visual Studio prompts you to convert the project.
  4. Build the project.
  5. Wait for the build to complete. It took approximately two minutes on my Lenovo T61p (dual core, 4 GB, Windows 7 64 bit). You should a line like this when it finishes successfully.
    ========== Build: 20 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
  6. Close Visual Studio.

Step 5 – Create a new project

  1. In Visual Studio 2008, go to File | New Project.
  2. Select Visual C++ | Empty Project.
  3. Give the project a name and click OK. I named this wxTest.

Step 6 – Create/Copy your source to this project.

  1. Right-click on the Project name and choose Open Folder in Windows Explorer. This will open to the home folder of your project. (Don’t right click the Solution name, make sure to right click the project under the solution name.)
  2. Open a second Windows Explore window.
  3. In the second window, browse to the wxWidgets sample directory and open the Minimal folder: C:\Dev\wxWidgets-2.8.10\samples\Minimal
    Note: You can choose other projects but you may want to start with Minimal and move on from there.
  4. Copy only the minimal.cpp and minimal.rc files to your project directory (the rest are not needed).
  5. Close the second window pointing to the C:\Dev\wxWidgets-2.8.10\samples\Minimal directory, it is not needed anymore.
  6. From the explorer window open to your project directory, use ctrl+click to highlight both the minimal.cpp and minimal.rc files.
  7. Drag both highlighted files into the Visual Studio Window and drop them over the project name.
    The minimal.cpp file should automatically be placed under the Source files section of your project.
    The minimal.rc file should automatically be placed under the Resource files section of your project.

Step 7 – Customize the project properties

  1. Right-click on the wxTest project and select Properties. (Don’t right click the Solution name, make sure to right click the project under the solution name.)
  2. In the top left of the properties window there is a Configuration drop down menu. Select All Configurations.
  3. Click to expand Configuration Properties.
  4. Click to expand C/C++.

    Note: If you don’t see a C/C++ section, then you don’t have any source files.  You need at least one C++ source file for this section to show up.

  5. Click to highlight General.
  6. Enter the following in Additional Include Directories.
    $(WXWIN)\include;$(WXWIN)\lib\vc_lib\mswd
  7. Click to highlight Preprocessor.
  8. Enter the following in Preprocessor Definitions.
    WIN32;__WXMSW__;_WINDOWS;_DEBUG;__WXDEBUG__
  9. Click to expand Linker.
  10. Click to highlight General.
  11. Enter the following in Additional Library Directories.
    $(WXWIN)\lib\vc_lib
  12. Click to highlight Input.
  13. Enter the following in Additional Dependencies.
    wxmsw28d_core.lib wxbase28d.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexd.lib wxexpatd.lib winmm.lib comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib

    Note: Not all of these libraries are required for this project, however, I list all of these because you may use some of them at some point. If you don’t think one is needed, remove it and recompile and if you don’t get errors, you were right, you probably didn’t need it.

  14. Click to expand Resources. (If you don’t see a Resources option, then you don’t have any files under resources so that is normal. Did you skip Step 5 because you probably should have added a resource in Step 5.)
  15. Click to highlight General.
  16. Enter the following in Preprocessor Definitions.
    _DEBUG;__WXMSW__;__WXDEBUG__;_WINDOWS;NOPCH
  17. Enter the following in Additional Include Directories.
    $(WXWIN)\include;$(WXWIN)\lib\vc_lib\mswd

You are now ready to build your wxWidgets application using Visual Studio 2008 on Windows 7.

Build your project and if you get any errors, go through it again, you probably missed a step (or I did, since I have already been caught with one step left out).

posted @ 2012-02-17 15:43 ivaneeo 阅读(518) | 评论 (0)编辑 收藏

最近发现bootstrap toolkit非常好用,现在收集一下sample网站:
1.http://twitter.github.com/bootstrap/(首先主站,可惜要fq)
2.http://webdesigntutsplus.s3.amazonaws.com/tuts/195_bootstrap/demo/main.html (也是一个简单的列子,可以作为参考)
3.http://www.breakingnews.com/ (新闻类网站,做的漂亮呀。。。)
4.http://www.mobile-loft.com/  (整体风格简洁)
5.http://demo.newfies-dialer.org/ (ajax登录的例子)
posted @ 2012-02-14 00:26 ivaneeo 阅读(1330) | 评论 (0)编辑 收藏

void ConvertGBKToUtf8(CString& strGBK) {
    int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
    unsigned short * wszUtf8 = new unsigned short[len+1];
    memset(wszUtf8, 0, len * 2 + 2);
    MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);

    len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
    char *szUtf8=new char[len + 1];
    memset(szUtf8, 0, len + 1);
    WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);

    strGBK = szUtf8;
    delete[] szUtf8;
    delete[] wszUtf8;
}

void ConvertUtf8ToGBK(CString& strUtf8) {
    int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
    unsigned short * wszGBK = new unsigned short[len+1];
    memset(wszGBK, 0, len * 2 + 2);
    MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, wszGBK, len);

    len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
    char *szGBK=new char[len + 1];
    memset(szGBK, 0, len + 1);
    WideCharToMultiByte (CP_ACP, 0, wszGBK, -1, szGBK, len, NULL,NULL);

    strUtf8 = szGBK;
    delete[] szGBK;
    delete[] wszGBK;
}
posted @ 2012-02-09 12:58 ivaneeo 阅读(1146) | 评论 (0)编辑 收藏

背景

        luacom是一个非常强大的模块,它使我们可以应用各种com组件,比如Word,但是,有一个问题,中文文件名它不识别。为什么呢?因为com内部是 unicode的,于是luacom要求所有输入都是utf-8的,而且luacom的输出也是utf-8的。这可肿么办啊?

iconv

        GNU有个libiconv库,要是有这个我们就不怕了! luaforge上搜索下,果然有lua-iconv,安装!

        luarocks install lua-iconv  不好意思,出错啦!出错的原因有两个:

  • 我们没有安装libiconv库
  • lua-iconv没有提供用cl编译的方法

自己编译lua-iconv

  1. 下载编译好的Windows版的 libiconv
  2. 下载 lua-iconv 源代码
  3. 解压 libiconv-1.9.1.bin.woe32.zip 文件,并将include目录添加为vs2008的包含文件目录,将lib目录添加为vs2008的库文件目录中(参见上一篇文章
  4. 解压lua-iconv的源代码
  5. vs2008新建一个空的Win32 DLL工程(参见上一篇文章),命名为luaiconv,将 luaiconv.c 文件添加到工程中
  6. 修改源代码:int luaopen_iconv(lua_State *L)  -> __declspec(dllexport) int luaopen_luaiconv(lua_State *L)
    • 注意:最后生成的dll文件名,必须和 luaopen_luaiconv 中的 luaiconv 一样(参见上一篇文章
  7. 项目属性 -> 链接器 -> 输入 -> 附加库文件 : lua51.lib iconv.lib charset.lib
  8. 编译生成release版的 luaiconv.dll 文件
  9. 将luaiconv.dll文件,以及libiconv-1.9.1.bin.woe32.zip解压出来的 iconv.dll(知道我为什么要改luaopen_iconv函数名了吧)和charset.dll文件一起拷贝到 luaforwindows的clibs目录中

测试

  1. require "luacom"  
  2. require "luaiconv"  
  3.   
  4. function createIconv(to, from)  
  5.     local cd = iconv.new(to, from)  
  6.     return function(txt)  
  7.         return cd:iconv(txt)  
  8.     end  
  9. end  
  10.   
  11. L = createIconv("utf-8", "gbk")  
  12.   
  13. -- 注意:运行本文件会修改 C:\你好word.docx 文件,请注意备份  
  14.   
  15. wordApp = assert(luacom.CreateObject("Word.Application"))  
  16. wordApp.Visible = true  
  17.   
  18. wordDocPath = L"C:\\你好word.docx"  
  19. if not pcall(function() wordDoc = wordApp.Documents:Open(wordDocPath) end) then  
  20.     wordDoc = wordApp.Documents:Add()  
  21. end  
  22.   
  23. wordApp.Selection:TypeText(L"你好word")  
  24. wordDoc:SaveAs2(wordDocPath, wdFormatDocument)  

以上测试代码,第一次运行时会创建 C:\你好word.docx 文件,以后再运行时会打开这个文件,每次运行都会输入 “你好word” 文字。如果你是Word 2003,那么,请将docx改为doc即可。

参考文献

http://hi.baidu.com/nivrrex/blog/item/17c231adad9e8a0f4b36d6ca.html

这位大哥自己用VC的函数写了转换函数,不过没有封装成库,而且我觉得写得不够简洁,用iconv库比较好,还不容易出错

http://www.cppblog.com/darkdestiny/archive/2009/04/25/81055.html

这位大哥,自己用iconv实现了转换,也没有封装成库。我的“L”函数也是从他这借来的,非常感谢!不过,我认为它这个相比我这个有两个弱点:

1、每次调用L函数,都要经过 iconv 打开、转换、关闭的过程,而我对一种形式的转换只需要打开一次(lua-iconv实现的^_^)

2、如果要实现反向转换,即utf-8到gbk,那么还得修改模块,而我这里就不用了(当然也是lua-iconv实现的^_^)

libiconv的说明
posted @ 2012-02-09 01:48 ivaneeo 阅读(616) | 评论 (0)编辑 收藏

Cocos2d-x 已经提供了对 Lua 的基本支持,但除了 Lua 的基本库外,并没有捆绑一些常用库,例如 LuaSocket。

经过一番尝试,终于搞定了此问题 :)

获得 LuaSocket 源代码后,在 cocos2d-x 项目的 libs/lua 目录中建立子目录 exts/luasocket,并将 luasocket-2.0.2/src 目录中所有的 *.c/*.h 文件拷贝到 libs/lua/exts/luasocket 目录中。

在 libs/lua/exts 目录中建立文件:

lualoadexts.h

#ifndef __LUALOADEXTS_H_ #define __LUALOADEXTS_H_  #include "lauxlib.h"  void luax_initpreload(lua_State *L);  #endif // __LUALOADEXTS_H_ 

lualoadexts.c

#include "lualoadexts.h"  // luasocket #include "luasocket.h" #include "mime.h"  static luaL_Reg luax_preload_list[] = {     {"socket.core", luaopen_socket_core},     {"mime.core", luaopen_mime_core},     {NULL, NULL} };  void luax_initpreload(lua_State *L) {     luaL_Reg* lib = luax_preload_list;     luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload",                    sizeof(luax_preload_list)/sizeof(luax_preload_list[0])-1);     for (; lib->func; lib++) {         lua_pushstring(L, lib->name);         lua_pushcfunction(L, lib->func);         lua_rawset(L, -3);     }     lua_pop(L, 1); } 

最后,打开 libs/lua/cocos2dx_support/LuaEngineImpl.cpp 文件,在 CCLuaScriptModule::CCLuaScriptModule() 构造函数最后载入 Lua 标准库和扩展库的代码:

CCLuaScriptModule::CCLuaScriptModule() {     d_ownsState = true;     d_state = lua_open();     luaL_openlibs(d_state);     int nOpen = tolua_Cocos2d_open(d_state);     CC_UNUSED_PARAM(nOpen);     nOpen = tolua_SimpleAudioEngine_open(d_state);     CC_UNUSED_PARAM(nOpen);      // init standard libraries     luaL_openlibs(d_state);     // init more libraries     luax_initpreload(d_state); } 

LuaScoket 除了 C 代码,还有一部分是 Lua 代码,所以需要将 luasocket-2.0.2/src/*.lua 复制到项目中,然后用下列 Lua 代码进行测试:

local socket = require("socket") print("socket module:", socket) print("socket.connect function:", socket.connect) print("socket.bind function:", socket.bind)  print("\n") print("io module:", io) 
posted @ 2012-02-08 00:03 ivaneeo 阅读(3999) | 评论 (0)编辑 收藏

将 Lua 源代码直接放入最终产品,显然不是个理想选择。利用 LOOP 提供的 Precompiler 工具,可以将 Lua 模块编译为 C 代码。

准备工作

LOOP 是一个 Lua 的 OOP 框架,Precompiler 则是 LOOP 中包含的一个工具。要安装 LOOP,得先安装 LuaRocks

$ wget http://luarocks.org/releases/luarocks-2.0.5.tar.gz $ tar zxf luarocks-2.0.5.tar.gz $ cd luarocks-2.0.5 $ ./configure $ make $ sudo make install 

然后安装 LOOP:

$ sudo luarocks install loop 

OK,现在准备工作完成了,接下来就是编译 Lua 模块为 C 代码。

编译

我们的框架中有一个 display.lua 模块,下面的代码可以将这个模块编译出来:

$ precompiler.lua -o luaqeeplayscripts -l "?.lua" -b -p qeeplay qeeplay/display.lua 

最后会得到 luaqeeplayscripts.c/.h 文件。其中定义了函数:

qeeplay int luaopen_qeeplay_display(lua_State *L); 

在上述命令行中,各个参数的意义如下:

-o: 指定输出文件名,例如 -o luaqeeplayscripts 会输出 luaqeeplayscripts.c/.h  -l: 指定推断 lua 模块名的模式,设定为 -l "?.lua" 就会以 lua 源文件名称作为模块名。     例如 display.lua 就是 display 模块。如果 display.lua 文件在 qeeplay 子目录中,     那么 qeeplay/display.lua 的模块名就是 qeeplay.display。  -b: 编译为字节码  -p: 函数定义的前缀,一般指定一个可以方便以后对生成的 .c/.h 文件进行再处理 

如果要将多个 lua 文件编译为一个 C 代码,可以添加更多的文件名到命令行中,例如:

$ precompiler.lua -o luasocketscripts -l "?.lua" -b -p socket \     socket.lua \     socket/url.lua \     socket/tp.lua \     socket/smtp.lua \     socket/mime.lua \     socket/ltn12.lua \     socket/http.lua \     socket/ftp.lua 

会创建 luasocketscripts.c/.h 文件,其中定义下列函数:

socket int luaopen_socket(lua_State *L); socket int luaopen_socket_url(lua_State *L); socket int luaopen_socket_tp(lua_State *L); socket int luaopen_socket_smtp(lua_State *L); socket int luaopen_socket_mime(lua_State *L); socket int luaopen_socket_ltn12(lua_State *L); socket int luaopen_socket_http(lua_State *L); socket int luaopen_socket_ftp(lua_State *L); 

载入编译好的 C 代码

利用前一篇文章中的 lualoadexts.c/lualoadexts.h,做一些修改即可:

luaqeeplayscripts.c

#include "lualoadexts.h"  // qeeplay #include "luaqeeplayscripts.h"  static luaL_Reg luax_preload_list[] = {     {"qeeplay.display", luaopen_qeeplay_display},     {NULL, NULL} };  void luax_initpreload(lua_State *L) {     .... } 

如果有更多模块需要载入,只需要 include 相应的头文件,并修改 luax_preload_list 定义即可。

posted @ 2012-02-08 00:01 ivaneeo 阅读(1079) | 评论 (0)编辑 收藏

今天在flex里通过addEventListener函数给控件动态加载click事件侦听函数时,除了事件本身传递的Event类型参数外,还需要传递更多的参数,在网上找了一段代码,用起来还不错,张贴到这里。

package
{
    public class EventArgExtend
    {
        public function EventArgExtend()
        {
        }
       
        public static function create(f:Function,... arg):Function
        {
               var F:Boolean=false;
               var _f:Function=function(e:*,..._arg)
               {
                   _arg=arg
                   if(!F)
                   {
                       F=true
                       _arg.unshift(e)
                   }
                   f.apply(null,_arg)
               };
               return _f;
          }
          public static function toString():String
          {
               return "Class JEventDelegate";
          }
    }
}

=========================================== 使用的方式:
txtShow.addEventListener(MouseEvent.CLICK,EventArgExtend.create(clickHandler,1,"str"));

            private function clickHandler(e:Event,...arg):void
            {
                Alert.show(arg[0].toString());
                Alert.show(arg[1].toString());
            }


还有另外一个方法,没有封装效果,不过代码更加容易理解:

var sayHello:String = "欢迎光临www.FlashJ.cn -Flash,Ria技术博客";
btn1.addEventListener(MouseEvent.CLICK,function (e:MouseEvent){clickHandlerWithArg(e,sayHello)});
function clickHandlerWithArg(e:MouseEvent,arg:String):void
{
var out:String= e.target + "发出事件(有参数) :" + arg;
trace(out);
}
posted @ 2011-12-16 17:43 ivaneeo 阅读(456) | 评论 (0)编辑 收藏

仅列出标题
共67页: First 上一页 9 10 11 12 13 14 15 16 17 下一页 Last