Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 95 lines (75 sloc) 3.159 kb
4caeb88 @jeremytregunna Added generate.io to addons dir. This script will be used to generate…
jeremytregunna authored
1 /*
2 * Generate an IoFooInit.c file for the Foo addon.
3 * Most of the logic was pulled from the old AddonBuilder.io so
4 * it's not a great solution, but it works.
5 */
6
7 Addon := Object clone do(
8 platform := System platform split at(0) asLowercase
1ffd508 @omf generate.io, OpenGL, Box, Image, Regex and Range on Windows/MinGW.
omf authored
9 onWindows := platform == "windows" or platform == "mingw"
4caeb88 @jeremytregunna Added generate.io to addons dir. This script will be used to generate…
jeremytregunna authored
10 isStatic := false
11
12 with := method(dir,
13 r := self clone
14 r setDirectory(dir)
15 r
16 )
17
18 // Force the user to clone the Addon.
19 init := method(
20 self directory ::= Directory clone
21 )
22
23 codeFolder := method(str, directory directoryNamed(str))
24 ioFiles := inlineMethod(codeFolder("io") filesWithExtension("io"))
25 initFileName := inlineMethod("source/Io#{directory name}Init.c" interpolate)
26
27 generateInit := method(
1ffd508 @omf generate.io, OpenGL, Box, Image, Regex and Range on Windows/MinGW.
omf authored
28 if(onWindows not and directory directoryNamed("source") filesWithExtension("m") size != 0, return)
4caeb88 @jeremytregunna Added generate.io to addons dir. This script will be used to generate…
jeremytregunna authored
29 initFile := directory fileNamed(initFileName) remove create open
30 initFile write("#include \"IoState.h\"\n")
31 initFile write("#include \"IoObject.h\"\n\n")
32
33 sourceFiles := directory directoryNamed("source") files
34 iocFiles := sourceFiles select(f, f name beginsWithSeq("Io") and(f name endsWithSeq(".c")) and(f name containsSeq("Init") not) and(f name containsSeq("_") not))
35 iocppFiles := sourceFiles select(f, f name beginsWithSeq("Io") and(f name endsWithSeq(".cpp")) and(f name containsSeq("Init") not) and(f name containsSeq("_") not))
36
37 iocFiles appendSeq(iocppFiles)
38 extraFiles := sourceFiles select(f, f name beginsWithSeq("Io") and(f name endsWithSeq(".c")) and(f name containsSeq("Init") not) and(f name containsSeq("_")))
39
40 orderedFiles := List clone appendSeq(iocFiles)
41
42 iocFiles foreach(f,
43 d := f open readLines detect(line, line containsSeq("docDependsOn"))
44 f close
45
46 if(d,
47 prerequisitName := "Io" .. d afterSeq("(\"") beforeSeq("\")") .. ".c"
48 prerequisit := orderedFiles detect(of, of name == prerequisitName )
49 orderedFiles remove(f)
50 orderedFiles insertAfter(f, prerequisit)
51 )
52 )
53
54 iocFiles = orderedFiles
55
56 iocFiles foreach(f,
57 initFile write("IoObject *" .. f name fileName .. "_proto(void *state);\n")
58 )
59
60 extraFiles foreach(f,
61 initFile write("void " .. f name fileName .. "Init(void *context);\n")
62 )
63
1ffd508 @omf generate.io, OpenGL, Box, Image, Regex and Range on Windows/MinGW.
omf authored
64 if (onWindows,
4caeb88 @jeremytregunna Added generate.io to addons dir. This script will be used to generate…
jeremytregunna authored
65 initFile write("__declspec(dllexport)\n")
66 )
67 initFile write("\nvoid Io" .. directory name .. "Init(IoObject *context)\n")
68 initFile write("{\n")
69 if(iocFiles size > 0,
70 initFile write("\tIoState *self = IoObject_state((IoObject *)context);\n\n")
71 )
72
73 iocFiles foreach(f,
74 initFile write("\tIoObject_setSlot_to_(context, SIOSYMBOL(\"" .. f name fileName asMutable removePrefix("Io") .. "\"), " .. f name fileName .. "_proto(self));\n\n")
75 )
76
77 extraFiles foreach(f,
78 initFile write("\t" .. f name fileName .. "Init(context);\n")
79 )
80
81 if(codeFolder("io") and isStatic,
82 ioFiles foreach(f, initFile write(codeForIoFile(f)))
83 )
84
85 initFile write("}\n")
86 initFile close
87 )
88 )
1dc942c @jeremytregunna Ticket #2 -- closed. Also added fixed some bugs in generate.io relate…
jeremytregunna authored
89
90 if(System args size > 2,
91 Addon with(Directory with("#{System args at(1)}/#{System args at(2)}" interpolate)) generateInit
92 ,
93 "#{System args at(0)}: Incorrect number of arguments. Need a path to addons dir and name of the addon." interpolate println
94 )
Something went wrong with that request. Please try again.