Mercurial > xcodescriptingbridge
annotate ScriptingBridge_Xcode.lua @ 2:5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
author | Eric Wing <ewing@anscamobile.com> |
---|---|
date | Fri, 29 Jul 2011 18:53:54 -0700 |
parents | |
children | d63043d62684 |
rev | line source |
---|---|
2
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
1 #!/Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
2 --[[ |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
3 Simple Scripting Bridge example using Xcode 3 to demonstrate automated building and running. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
4 --]] |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
5 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
6 LuaCocoa.import("ScriptingBridge") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
7 LuaCocoa.import("Foundation") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
8 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
9 function GetURLFromFileAndPath(file_name) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
10 local current_working_directory = NSFileManager:defaultManager():currentDirectoryPath() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
11 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
12 local file_string = NSString:stringWithUTF8String_(file_name):stringByExpandingTildeInPath():stringByStandardizingPath() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
13 if not file_string:isAbsolutePath() then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
14 file_string = current_working_directory:stringByAppendingPathComponent_(file_string):stringByStandardizingPath() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
15 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
16 --print("file_string", file_string) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
17 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
18 local ns_url = NSURL:URLWithString_(file_string:stringByAddingPercentEscapesUsingEncoding_(NSUTF8StringEncoding)) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
19 --print("ns_url", ns_url) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
20 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
21 return ns_url |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
22 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
23 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
24 local xcode_application = SBApplication:applicationWithBundleIdentifier_("com.apple.Xcode") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
25 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
26 if xcode_application ~= nil then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
27 -- arg[0] is the script name |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
28 -- arg[1] is either 'os' or 'simulator' |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
29 -- negative index values represent arguments that come before the script |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
30 -- we only want the arguments after the script name |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
31 -- so use a numeric for |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
32 local file_to_open = arg[1] or "MySampleProject.xcodeproj" |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
33 local url_to_open = GetURLFromFileAndPath(file_to_open) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
34 local xcode_document = xcode_application:open(url_to_open) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
35 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
36 local simulator_or_device = arg[2] or "os" |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
37 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
38 -- The sample project has "Debug" and "Release" configurations to choose from. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
39 local build_configuration_type = "Release" |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
40 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
41 --[[ |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
42 local all_documents = xcode_application:projects() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
43 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
44 print(all_documents, #all_documents) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
45 for i=1, #all_documents do |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
46 local a_doc = all_documents[i] |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
47 print("doc", a_doc) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
48 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
49 --]] |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
50 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
51 -- I'm assuming that the document we just opened becomes the activeProjectDocument |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
52 local active_project_document = xcode_application:activeProjectDocument() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
53 print("active_project", active_project_document, active_project_document:name(), active_project_document:path()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
54 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
55 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
56 local xcode_project = active_project_document:project() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
57 print(xcode_project, xcode_project:name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
58 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
59 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
60 -- This could be a problem: activeSDK() is nil. Looks like an Apple bug. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
61 -- Hmmm, Sometimes it works. I don't understand this. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
62 -- iphoneos4.2 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
63 -- iphonesimulator4.2 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
64 print("activeSDK", xcode_project:activeSDK()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
65 local active_sdk = tostring(xcode_project:activeSDK()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
66 print("active_sdk", active_sdk) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
67 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
68 if not string.match(active_sdk, simulator_or_device) then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
69 if "simulator" == simulator_or_device then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
70 local sdk = string.gsub(active_sdk, "os", "simulator") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
71 print("sdk", sdk) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
72 xcode_project:setActiveSDK(sdk) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
73 else |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
74 local sdk = string.gsub(active_sdk, "simulator", "os") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
75 print("sdk", sdk) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
76 xcode_project:setActiveSDK(sdk) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
77 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
78 print("changed activeSDK", xcode_project:activeSDK()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
79 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
80 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
81 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
82 -- I don't think we need to worry about setting the architexture since we build Universal (fat) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
83 -- However, have seen Xcode get into weird states when switching between simulator and device. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
84 -- Sometimes you need to set this and verify you actually changed it. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
85 -- xcode_project:setActiveArchitecture("armv7") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
86 -- xcode_project:setActiveArchitecture("i386") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
87 -- print("activeArchitecture", xcode_project:activeArchitecture()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
88 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
89 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
90 -- I'm unclear on buildConfigurations vs buildConfigurationTypes |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
91 -- I don't think we need to use buildConfigurations |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
92 --[[ |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
93 local array_of_build_configurations = xcode_project:buildConfigurations() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
94 for i=1, #array_of_build_configurations do |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
95 print("buildConfigurations[:".. tostring(i) .. "]" .. array_of_build_configurations[i]:name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
96 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
97 --]] |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
98 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
99 local array_of_build_configuration_types = xcode_project:buildConfigurationTypes() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
100 local desired_build_configuration_type = nil |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
101 for i=1, #array_of_build_configuration_types do |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
102 print("buildConfigurationType[".. tostring(i) .. "]" .. array_of_build_configuration_types[i]:name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
103 -- Xcode is acting weird. It seems to overwrite entries and replace them, but I don't think it is actually |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
104 -- replacing them. We need to pick the right element. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
105 -- For us, Release is the 2nd position, not the first. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
106 if tostring(array_of_build_configuration_types[i]:name()) == tostring(build_configuration_type) then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
107 desired_build_configuration_type = array_of_build_configuration_types[i] |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
108 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
109 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
110 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
111 local array_of_executables = xcode_project:executables() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
112 for i=1, #array_of_executables do |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
113 print("executables[".. tostring(i) .. "]" .. array_of_executables[i]:name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
114 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
115 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
116 local array_of_targets = xcode_project:targets() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
117 local active_target = xcode_project:activeTarget() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
118 for i=1, #array_of_targets do |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
119 print("targets[".. tostring(i) .. "]" .. array_of_targets[i]:name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
120 -- Watch out: __eq (==) always returns false for different types. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
121 local the_name = array_of_targets[i]:name() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
122 if tostring(the_name) == "OpenGLES2" then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
123 active_target = array_of_targets[i] |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
124 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
125 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
126 xcode_project:setActiveTarget_(active_target) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
127 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
128 --print("config type", xcode_project:activeBuildConfigurationType():name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
129 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
130 -- You are not allowed to create a new instance of XcodeBuildConfigurationType |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
131 -- Instead, you must use an object returned from the system. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
132 -- It appears you cannot use copy or mutableCopy as they throw exceptions. |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
133 -- XcodeBuildConfigurationType = NSClassFromString("XcodeBuildConfigurationType") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
134 -- local build_configuration_type = XcodeBuildConfigurationType:alloc():init() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
135 -- copy and mutableCopy throw exceptions |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
136 local active_build_configuration_type = xcode_project:activeBuildConfigurationType() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
137 if active_build_configuration_type ~= desired_build_configuration_type then |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
138 print("desired_build_configuration_type", desired_build_configuration_type) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
139 xcode_project:setActiveBuildConfigurationType_(desired_build_configuration_type) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
140 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
141 -- Calling name() sometimes fails and crashes Xcode 3.2.6 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
142 -- print("config type", xcode_project:activeBuildConfigurationType():name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
143 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
144 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
145 local active_executable = xcode_project:activeExecutable() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
146 print(active_executable, active_executable:name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
147 active_executable:setName_("OpenGLES2") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
148 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
149 print("ActiveTarget:", xcode_project:activeTarget():name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
150 print("ActiveExecutable:", xcode_project:activeExecutable():name()) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
151 ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, build_configuration_type) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
152 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
153 -- local build_configuration_type = |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
154 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
155 print(ret_string) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
156 print("launching...") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
157 -- Refetch the object just in case since we tried changing it |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
158 active_executable = xcode_project:activeExecutable() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
159 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
160 -- launch() doesn't seem to actually work. We must use debug() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
161 -- local ret_string = active_executable:launch() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
162 local ret_string = active_executable:debug() |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
163 print(ret_string) |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
164 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
165 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
166 else |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
167 print("Xcode not available") |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
168 end |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
169 |
5c54957c04c5
Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff
changeset
|
170 |