Index: nacltoons/bindings/basic.lua |
diff --git a/nacltoons/bindings/basic.lua b/nacltoons/bindings/basic.lua |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c4e1440e3d7d99561bf52609745c5cb5a1fb8915 |
--- /dev/null |
+++ b/nacltoons/bindings/basic.lua |
@@ -0,0 +1,86 @@ |
+--- Helper script for generating bindings with tolua++ |
+-- This file is based on the file of the same name which ships |
+-- as part of cocos2dx. |
+-- example usage: |
+-- tolua++ -L basic.lua -o LuaCocos2d.cpp Cocos2d.pkg |
+ |
+_is_functions = _is_functions or {} |
+_to_functions = _to_functions or {} |
+_push_functions = _push_functions or {} |
+ |
+local CCObjectTypes = { |
+ "CCPhysicsSprite", |
+} |
+ |
+-- register CCObject types |
+for i = 1, #CCObjectTypes do |
+ _push_functions[CCObjectTypes[i]] = "toluafix_pushusertype_ccobject" |
+end |
+ |
+-- register LUA_FUNCTION, LUA_TABLE, LUA_HANDLE type |
+_to_functions["LUA_FUNCTION"] = "toluafix_ref_function" |
+_is_functions["LUA_FUNCTION"] = "toluafix_isfunction" |
+_to_functions["LUA_TABLE"] = "toluafix_totable" |
+_is_functions["LUA_TABLE"] = "toluafix_istable" |
+ |
+local toWrite = {} |
+local currentString = '' |
+local out |
+local WRITE, OUTPUT = write, output |
noelallen1
2013/03/08 21:52:01
What are these circular definitions?
Sam Clegg
2013/03/08 22:22:53
What this code is doing is intercepting/overwritin
|
+ |
+function output(s) |
+ out = _OUTPUT |
+ output = OUTPUT -- restore |
+ output(s) |
+end |
+ |
+function write(a) |
+ if out == _OUTPUT then |
+ currentString = currentString .. a |
+ if string.sub(currentString,-1) == '\n' then |
+ toWrite[#toWrite+1] = currentString |
+ currentString = '' |
+ end |
+ else |
+ WRITE(a) |
noelallen1
2013/03/08 21:52:01
what is the difference between write and WRITE?
Sam Clegg
2013/03/08 22:22:53
WRITE() is the original write() as defined by tolu
|
+ end |
+end |
+ |
+function post_output_hook(package) |
+ local result = table.concat(toWrite) |
+ local function replace(pattern, replacement) |
+ local k = 0 |
+ local nxt, currentString = 1, '' |
+ repeat |
+ local s, e = string.find(result, pattern, nxt, true) |
+ if e then |
+ currentString = currentString .. string.sub(result, nxt, s-1) .. replacement |
+ nxt = e + 1 |
+ k = k + 1 |
+ end |
+ until not e |
+ result = currentString..string.sub(result, nxt) |
+ if k == 0 then print('Pattern not replaced', pattern) end |
+ end |
+ |
+ replace([[#ifndef __cplusplus |
+#include "stdlib.h" |
+#endif |
+]], |
+ [[// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+#ifndef __cplusplus |
+#include "stdlib.h" |
+#endif |
+]]) |
+ |
+ if string.find(result, 'toluafix_pushusertype_ccobject') then |
+ replace([[toluafix_pushusertype_ccobject(tolua_S,(void*)tolua_ret]], |
+ [[int nID = (tolua_ret) ? (int)tolua_ret->m_uID : -1; |
+ int* pLuaID = (tolua_ret) ? &tolua_ret->m_nLuaID : NULL; |
+ toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret]]) |
+ end |
+ |
+ WRITE(result) |
+end |