1.

lua函数都在refid_fun

refid_fun[refid] = fun

TOLUA_API int toluafix_ref_function(lua_State* L, int lo, int def)
{
// function at lo
if (!lua_isfunction(L, lo)) return ; s_function_ref_id++; lua_pushstring(L, TOLUA_REFID_FUNCTION_MAPPING);
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: fun ... refid_fun */
lua_pushinteger(L, s_function_ref_id); /* stack: fun ... refid_fun refid */
lua_pushvalue(L, lo); /* stack: fun ... refid_fun refid fun */ lua_rawset(L, -); /* refid_fun[refid] = fun, stack: fun ... refid_ptr */
lua_pop(L, ); /* stack: fun ... */ return s_function_ref_id; // lua_pushvalue(L, lo); /* stack: ... func */
// return luaL_ref(L, LUA_REGISTRYINDEX);
}
static int tolua_Cocos2d_CCScriptEventDispatcher_addNodeEventListener00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,,"CCScriptEventDispatcher",,&tolua_err) ||
!tolua_isnumber(tolua_S,,,&tolua_err) ||
(tolua_isvaluenil(tolua_S,,&tolua_err) || !toluafix_isfunction(tolua_S,,"LUA_FUNCTION",,&tolua_err)) ||
!tolua_isnumber(tolua_S,,,&tolua_err) ||
!tolua_isnoobj(tolua_S,,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
CCScriptEventDispatcher* self = (CCScriptEventDispatcher*) tolua_tousertype(tolua_S,,);
int event = ((int) tolua_tonumber(tolua_S,,));
LUA_FUNCTION listener = ( toluafix_ref_function(tolua_S,,));
int tag = ((int) tolua_tonumber(tolua_S,,));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'addScriptEventListener'", NULL);
#endif
{
int tolua_ret = (int) self->addScriptEventListener(event,listener,tag);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return ;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'addNodeEventListener'.",&tolua_err);
return ;
#endif
}

比如;lua代码item:addNodeEventListener,CCScriptEventDispatcher* self===item,int event===cc.MENU_ITEM_CLICKED_EVENT,

LUA_FUNCTION listener =
function(tag)
if sound then audio.playSound(sound) end
listener(tag)
end
--[[--

创建一个文字标签菜单项,并返回 CCMenuItemLabel 对象。

可用参数:

-   listener: 回调函数
- tag: 按钮的 Tag,会传入回调函数。多个按钮使用同一个回调函数时,可根据 Tag 区分哪一个按钮被按下(可选)
- x, y: 坐标(可选)
- sound: 按钮按下时播放什么音效(可选) 以及所有可以用于 ui.newTTFLabel() 的参数。 @param table params 参数表格对象 @return CCMenuItemLabel CCMenuItemLabel对象 ]] function ui.newTTFLabelMenuItem(params)
local p = clone(params)
p.x, p.y = nil, nil
local label = ui.newTTFLabel(p) local listener = params.listener
local tag = params.tag
local x = params.x
local y = params.y
local sound = params.sound local item = CCMenuItemLabel:create(label)
if item then
if type(listener) == "function" then
item:addNodeEventListener(cc.MENU_ITEM_CLICKED_EVENT, function(tag)
if sound then audio.playSound(sound) end
listener(tag)
end)
end
if x and y then item:setPosition(x, y) end
if tag then item:setTag(tag) end
end return item
end self.item1 = ui.newTTFLabelMenuItem({text = "计时模式", size = , align = ui.TEXT_ALIGN_CENTER,
x = display.cx, y = display.cy + , color = display.COLOR_GREEN,
listener = function()
app:setData("currentLv", )
app:enterScene("MainScene",)
end})
int CCLuaStack::executeFunctionByHandler(int nHandler, int numArgs)
{
int ret = ;
if (pushFunctionByHandler(nHandler)) /* L: ... arg1 arg2 ... func */
{
if (numArgs > )
{
lua_insert(m_state, -(numArgs + )); /* L: ... func arg1 arg2 ... */
}
ret = executeFunction(numArgs);
}
return ret;
}

http://blog.csdn.net/linchaolong/article/details/37657077

http://www.cppblog.com/kevinlynx/archive/2011/04/24/144905.html

http://blog.csdn.net/rain_qingtian/article/details/48573981

http://blog.csdn.net/lightxm/article/details/38435067

http://www.cnblogs.com/boliu/p/4091274.html

第9月第13天 传递lua匿名函数到c/c++的更多相关文章

  1. 巧用javascript对象属性,向事件绑定的匿名函数内传递循环控制变量的值

    遇到一个需要向匿名函数传递循环控制变量的问题,我受到园子里这篇文章的启发[笔记]js获取当前点击元素的索引,解决了这个问题.现在把代码贴出来,以防止自己忘记. if ($('#labModal').l ...

  2. Lua基础 函数(一)

    转自: http://blog.csdn.net/wzzfeitian/article/details/8653101 在Lua中,函数是对语句和表达式进行抽象的主要方法.既可以用来处理一些特殊的工作 ...

  3. 巨蟒python全栈开发-第13天 内置函数 匿名函数lambda

    一.今日内容总览 1.内置函数(1):并不是每一个内置函数都是那么常用 上菜:内置函数部分//思维导图:https://www.processon.com/view/link/5b4ee15be4b0 ...

  4. lua基础---函数

    Lua的函数功能很强大,保留了C语言的一些基本的特性,但是也有C语言没有的特性,比如,lua可以在一个函数返回多个值,我们来看看下面这个案例: 解释运行: lua test5.lua --定义一个函数 ...

  5. lua的函数初识

    学习到Lua的函数.认为有必要记下来. 參考教程:Programming in Lua 函数能够以表达式或陈述语句出现,例如以下所看到的: print(8*9, 9/8) a = math.sin(3 ...

  6. Lua 常用函数 一

    lua_getallocf lua_Alloc lua_getallocf (lua_State *L, void **ud); 返回给定状态机的内存分配器函数.如果 ud 不是 NULL ,Lua ...

  7. lua闭合函数

    function count( ... ) return function( ... ) i = i+ return i end end local func = count(...) print(f ...

  8. Lua function 函数

    Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...

  9. lua API函数大全

    Lua5.1中的API函数 lua_State* luaL_newstate()Lua脚本的编译执行是相互独立的,在不同的线程上执行.通过luaL_newstate()函数可以申请一个虚拟机,返回指针 ...

随机推荐

  1. c++之洛谷P1068分数线划定

    这是个排序题,做题过程中对sort的理解加深了不少,记下来避免忘记. 题目来源:https://www.luogu.org/problemnew/show/P1068 题目描述 世博会志愿者的选拔工作 ...

  2. [咸恩静][Love effect]

    歌词来源:http://music.163.com/#/song?id=31877654 作曲 : Monster Factory/양승욱 [作曲 : Monster Factory/yang-seu ...

  3. 每天学一点---document.createDocumentFragment

    document.createDocumentFragment  用于创建文档对象,创建好的对象存在于内存中(不会引起回流,对元素位置和几何上的运算),不是附着在DOM树上,所以有更好的性能 可将该文 ...

  4. centos 升级python2.6 到python3.3(实测可行)

    http://blog.csdn.net/harith/article/details/17538233

  5. 第三次spring冲刺2

    完成了对错题的收集,和做错题的功能,运用了android自带的SQLite数据库.

  6. ElasticSearch 2 (33) - 信息聚合系列之聚合过滤

    ElasticSearch 2 (33) - 信息聚合系列之聚合过滤 摘要 聚合范围限定还有一个自然的扩展就是过滤.因为聚合是在查询结果范围内操作的,任何可以适用于查询的过滤器也可以应用在聚合上. 版 ...

  7. Linux命令(十一) 显示文件类型 file

    命令介绍 file 命令是用来显示文件的类型,对于每个给定的参数,该命令试图将文件分类,分辨的类型有文本文件.可执行文件.压缩文件.或其它可理解的数据格式. 常用参数介绍 -b 不显示文件名称,只显示 ...

  8. vue组件间的数据和方法传递

    方法 1.父组件调用子组件:ref(在子组件中加上ref即可通过this.$refs.ref.method调用) 2.子组件调用父组件:emit(this.$emit(调用的方法名,传递的参数)) 数 ...

  9. js & parseFloat & toFixed

    js & parseFloat & toFixed https://repl.it/languages/javascript https://repl.it/repls/MintyBa ...

  10. Docker一些常用命令

    1.启动Docker服务 service docker start 2.查看所有镜像 docker images 3.查看正在运行的容器 docker ps 4.查看所有容器 docker ps -a ...