Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: nacltoons/bindings/basic.lua

Issue 12634010: [nacltoons] Add Makefile for building lua bindings. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 --- Helper script for generating bindings with tolua++
2 -- This file is based on the file of the same name which ships
3 -- as part of cocos2dx.
4 -- example usage:
5 -- tolua++ -L basic.lua -o LuaCocos2d.cpp Cocos2d.pkg
6
7 _is_functions = _is_functions or {}
8 _to_functions = _to_functions or {}
9 _push_functions = _push_functions or {}
10
11 local CCObjectTypes = {
12 "CCPhysicsSprite",
13 }
14
15 -- register CCObject types
16 for i = 1, #CCObjectTypes do
17 _push_functions[CCObjectTypes[i]] = "toluafix_pushusertype_ccobject"
18 end
19
20 -- register LUA_FUNCTION, LUA_TABLE, LUA_HANDLE type
21 _to_functions["LUA_FUNCTION"] = "toluafix_ref_function"
22 _is_functions["LUA_FUNCTION"] = "toluafix_isfunction"
23 _to_functions["LUA_TABLE"] = "toluafix_totable"
24 _is_functions["LUA_TABLE"] = "toluafix_istable"
25
26 local toWrite = {}
27 local currentString = ''
28 local out
29 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
30
31 function output(s)
32 out = _OUTPUT
33 output = OUTPUT -- restore
34 output(s)
35 end
36
37 function write(a)
38 if out == _OUTPUT then
39 currentString = currentString .. a
40 if string.sub(currentString,-1) == '\n' then
41 toWrite[#toWrite+1] = currentString
42 currentString = ''
43 end
44 else
45 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
46 end
47 end
48
49 function post_output_hook(package)
50 local result = table.concat(toWrite)
51 local function replace(pattern, replacement)
52 local k = 0
53 local nxt, currentString = 1, ''
54 repeat
55 local s, e = string.find(result, pattern, nxt, true)
56 if e then
57 currentString = currentString .. string.sub(result, nxt, s-1) .. replacement
58 nxt = e + 1
59 k = k + 1
60 end
61 until not e
62 result = currentString..string.sub(result, nxt)
63 if k == 0 then print('Pattern not replaced', pattern) end
64 end
65
66 replace([[#ifndef __cplusplus
67 #include "stdlib.h"
68 #endif
69 ]],
70 [[// Copyright (c) 2013 The Chromium Authors. All rights reserved.
71 // Use of this source code is governed by a BSD-style license that can be
72 // found in the LICENSE file.
73 #ifndef __cplusplus
74 #include "stdlib.h"
75 #endif
76 ]])
77
78 if string.find(result, 'toluafix_pushusertype_ccobject') then
79 replace([[toluafix_pushusertype_ccobject(tolua_S,(void*)tolua_ret]],
80 [[int nID = (tolua_ret) ? (int)tolua_ret->m_uID : -1;
81 int* pLuaID = (tolua_ret) ? &tolua_ret->m_nLuaID : NULL;
82 toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret]])
83 end
84
85 WRITE(result)
86 end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698