ua 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ #include <windows.h>
2
+ LRESULT CALLBACK wndproc(HWND h, UINT m, WPARAM w, LPARAM l){
3
+ if(m == WM_CLOSE || m == WM_QUIT || m == WM_DESTROY){
4
+ PostQuitMessage(0);
5
+ return 0;
6
+ }
7
+ if(m == WM_COMMAND){
8
+ if(HIWORD(w) == BN_CLICKED){
9
+
10
+
11
+ if(LOWORD(w) == 101){
12
+ MessageBox(0, "Clicked", 0, 48);
13
+ }
14
+
15
+
16
+ }
17
+ }
18
+ return DefWindowProc(h, m, w, l);
19
+ }
20
+
21
+ WNDCLASSEX wc = {sizeof(wc), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, wndproc, 0, 0, 0, LoadIcon(0, IDI_APPLICATION), LoadCursor(0, IDC_ARROW), (HBRUSH)1, "", "Hello", LoadIcon(0, IDI_APPLICATION)};
22
+ int main(){
23
+ RegisterClassEx(&wc);
24
+ HWND main = CreateWindowEx(0, "Hello", "Hello world", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
25
+ 300,200,640,480,
26
+ 0, 0, 0, 0
27
+ );
28
+
29
+ CreateWindowEx(0, "button", "Hello", WS_CHILD | WS_VISIBLE,
30
+ 0,0,24,36,
31
+ main, (HMENU)101, 0, 0);
32
+
33
+
34
+ MSG msg;
35
+ while(GetMessage(&msg, 0, 0, 0) > 0){
36
+ DispatchMessage(&msg);
37
+ TranslateMessage(&msg);
38
+ }
39
+ }
data/test/m.html ADDED
@@ -0,0 +1,88 @@
1
+
2
+ <!doctype html>
3
+ <html>
4
+ <head>
5
+ <title> Hello </title>
6
+ </head>
7
+ <body>
8
+
9
+ <input id="object_11"></input>
10
+
11
+ <div id="object_14"></div>
12
+
13
+ <input id="object_16"></input>
14
+
15
+ <input id="object_19"></input>
16
+
17
+ <div id="object_22"></div>
18
+
19
+
20
+ <script>
21
+ $scope = {}
22
+ $views = {}
23
+ window.update = function(a){
24
+ $views[a].forEach(function(f, i){
25
+ f.update();
26
+ })
27
+ }
28
+
29
+ document.querySelector("#object_11").oninput = function(){
30
+ ($scope)["a"] = this.value
31
+ update("a")
32
+ }
33
+
34
+
35
+ if(typeof $views["a"] === 'undefined'){
36
+ $views["a"] = []
37
+ }
38
+ $views["a"].push(document.querySelector("#object_14"))
39
+
40
+ document.querySelector("#object_14").update = function(){
41
+
42
+ this.innerHTML = "Your name has changed to " + ($scope)["a"]+ ""
43
+ }
44
+
45
+ document.querySelector("#object_16").oninput = function(){
46
+ ($scope)["op1"] = this.value
47
+ update("op1")
48
+ }
49
+
50
+ document.querySelector("#object_19").oninput = function(){
51
+ ($scope)["op2"] = this.value
52
+ update("op2")
53
+ }
54
+
55
+
56
+ if(typeof $views["result"] === 'undefined'){
57
+ $views["result"] = []
58
+ }
59
+ $views["result"].push(document.querySelector("#object_22"))
60
+
61
+ if(typeof $views["op1"] === 'undefined'){
62
+ $views["op1"] = []
63
+ }
64
+ $views["op1"].push(document.querySelector("#object_22"))
65
+
66
+ if(typeof $views["op2"] === 'undefined'){
67
+ $views["op2"] = []
68
+ }
69
+ $views["op2"].push(document.querySelector("#object_22"))
70
+
71
+ document.querySelector("#object_22").update = function(){
72
+
73
+ ($scope)["result"] = +($scope)["op1"] * +($scope)["op2"]
74
+
75
+ this.innerHTML = "Your answer is " + ($scope)["result"]+ ""
76
+ }
77
+
78
+
79
+
80
+ document.querySelector("#object_11").oninput()
81
+
82
+ document.querySelector("#object_16").oninput()
83
+
84
+ document.querySelector("#object_19").oninput()
85
+
86
+ </script>
87
+ </body>
88
+
data/test/temp.2.cpp ADDED
@@ -0,0 +1,5 @@
1
+
2
+ extern "C" int __stdcall func(int a,int b){
3
+ return ((a)+(b));
4
+ }
5
+
data/test/temp.4.cpp ADDED
@@ -0,0 +1,5 @@
1
+
2
+ extern "C" int __stdcall func(int a,int b){
3
+ return ((a)+(b));
4
+ }
5
+
data/test/test.js ADDED
@@ -0,0 +1,13 @@
1
+
2
+ (function(){
3
+ if(typeof window !== 'undefined') {
4
+ window.alert("abc" );
5
+ }
6
+ if(typeof console !== 'undefined') {
7
+ console.log( "abc" );
8
+ }
9
+ if(typeof WScript !== 'undefined') {
10
+ WScript.Echo( "abc" );
11
+ }
12
+ })()
13
+
data/test/test.rb ADDED
@@ -0,0 +1,74 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+ require 'cgi'
4
+
5
+ stream "com.ua.root", "com.ua.main"
6
+ add "com.ua.main", "title", "charset", "content", "css", "js" do
7
+ %{
8
+ <!doctype html>
9
+ <head>
10
+ <title><%= title %> </title>
11
+ <meta http-equiv="content-type" Content="text/html; Charset=<%= charset %>" >
12
+ <style>
13
+ <%= context(css, :app) %>
14
+ </style>
15
+ <script>
16
+ <%= context(js, :app) %>
17
+ </script>
18
+ </head>
19
+ <body>
20
+ <%= context(content, :html) %>
21
+ </body>
22
+ </html>
23
+ }
24
+ end
25
+
26
+ context String, :shell do |str|
27
+ `#{str}`
28
+ end
29
+
30
+ context String, :html do |str|
31
+ CGI.escapeHTML str
32
+ end
33
+
34
+ context String, :css_attr do |str|
35
+ str.tr("_", "-")
36
+ end
37
+
38
+ context Object, :css_value do |any|
39
+ any
40
+ end
41
+
42
+ add "com.ua.cssText", "name", "value", "sel" do
43
+ "<%=sel%> { <%= context(name, :css_attr)%> : <%= context(value, :css_value) %>; }\n"
44
+ end
45
+
46
+ class CSSBuilder
47
+ def initialize(name)
48
+ @name = name
49
+ end
50
+ def method_missing(sym, value)
51
+ r = create "com.ua.cssText"
52
+ r.name = sym.to_s
53
+ r.value = value
54
+ r.sel = @name
55
+ append "com.ua.css", r
56
+ self
57
+ end
58
+ end
59
+
60
+ def css(name)
61
+ CSSBuilder.new(name)
62
+ end
63
+
64
+
65
+ x = get "com.ua.main"
66
+ x.title = "Hello world"
67
+ x.charset = "GBK"
68
+ x.css = add "com.ua.css"
69
+ x.js = add "com.ua.js"
70
+ x.content = context("dir", :shell)
71
+ cssbody = css("body")
72
+ cssbody.text_decoration("underline").font_size("48px")
73
+ go!
74
+
data/test/test2.rb ADDED
@@ -0,0 +1,41 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+
4
+ class SayHelloApplication < Ua::Application
5
+ def initialize
6
+ super
7
+ stream "com.ua.root", "com.ua.js.run"
8
+ add "com.ua.js.main" do
9
+ "
10
+ (function(){
11
+ if(typeof console !== 'undefined') {
12
+ console.log( <%= context(message, :js_string) %> );
13
+ }
14
+ })()
15
+ "
16
+ end
17
+ add "com.ua.js.run" do
18
+ "<%
19
+ IO.binwrite('test.js', context(get('com.ua.js.main'), :app))
20
+ context(execjs || 'node.exe', :shell, 'test.js')
21
+ %>"
22
+ end
23
+
24
+ context String, :js_string do |str|
25
+ str.inspect # should be quote_string(str), but this partly works
26
+ end
27
+
28
+ context String, :shell do |*args|
29
+ `#{args.join(" ")}`
30
+ end
31
+ end
32
+ end
33
+
34
+ def say_hello(hello = "Hello world")
35
+ app = SayHelloApplication.new
36
+ app.get('com.ua.js.main').message = hello
37
+ app.get('com.ua.js.run').execjs = "wscript.exe"
38
+ app.go!
39
+ end
40
+
41
+ say_hello "abc"
data/test/test3.rb ADDED
@@ -0,0 +1,111 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+
4
+ class SimpleWin32Application < Ua::Application
5
+ def initialize
6
+ super
7
+ stream "com.ua.root", "com.win32.runner"
8
+ add "com.win32.runner" do
9
+ "<%
10
+ context('com.win32.cpp', :write)
11
+ cflags = context(get('com.win32.cflags'), :shellwords)
12
+ ldflags = context(get('com.win32.ldflags'), :shellwords)
13
+ arr = ['g++', 'com.win32.cpp'] + cflags + ldflags
14
+ context(arr, :shell)
15
+ context(['win32.exe'], :shell)
16
+ %>
17
+ "
18
+ end
19
+ add "com.win32.cpp" do
20
+ DATA.read
21
+ end
22
+ add 'com.win32.cflags'
23
+ add 'com.win32.ldflags'
24
+ add 'com.win32.buttons'
25
+ append 'com.win32.ldflags', '-o', 'win32.exe'
26
+ context UAClass, :shellwords do |a|
27
+ get(a.stream_)
28
+ end
29
+ context Array, :shell do |a|
30
+ `#{a.join(' ')}`
31
+ end
32
+ context Array, :bound do |a|
33
+ "#{a.join(",")}"
34
+ end
35
+ context String, :write do |a|
36
+ IO.binwrite(a, app(a))
37
+ end
38
+ context String, :cstring do |str|
39
+ str.inspect
40
+ end
41
+ add "com.win32.button" do
42
+ %{
43
+ CreateWindowEx(0, "button", <%= context(text, :cstring) %>, WS_CHILD | WS_VISIBLE,
44
+ <%= context(bound, :bound) %>,
45
+ main, (HMENU)<%= id %>, 0, 0);
46
+
47
+ }
48
+ end
49
+
50
+ add "com.win32.buttonclicks" do
51
+ %{
52
+ <% get(stream_).each{|obj| %>
53
+ if(LOWORD(w) == <%= obj.id %>){
54
+ MessageBox(0, <%= context(obj.msg, :cstring) %>, 0, 48);
55
+ }
56
+ <% } %>
57
+ }
58
+ end
59
+ end
60
+
61
+ def button(x, y, w, h, text, msg)
62
+ @id ||= 100
63
+ @id += 1
64
+ btn = create 'com.win32.button',
65
+ bound: [x, y, w, h],
66
+ text: text,
67
+ msg: msg,
68
+ id: @id
69
+
70
+ append 'com.win32.buttons', btn
71
+ append 'com.win32.buttonclicks', btn
72
+ btn
73
+ end
74
+ end
75
+
76
+
77
+ x = SimpleWin32Application.new
78
+ x.get('com.win32.cpp').title = "Hello world"
79
+ x.get('com.win32.cpp').bound = [300, 200, 640, 480]
80
+ x.button 0, 0, 24, 36, "Hello", "Clicked"
81
+ x.go!
82
+
83
+ __END__
84
+ #include <windows.h>
85
+ LRESULT CALLBACK wndproc(HWND h, UINT m, WPARAM w, LPARAM l){
86
+ if(m == WM_CLOSE || m == WM_QUIT || m == WM_DESTROY){
87
+ PostQuitMessage(0);
88
+ return 0;
89
+ }
90
+ if(m == WM_COMMAND){
91
+ if(HIWORD(w) == BN_CLICKED){
92
+ <%= context(get("com.win32.buttonclicks"), :app) %>
93
+ }
94
+ }
95
+ return DefWindowProc(h, m, w, l);
96
+ }
97
+
98
+ WNDCLASSEX wc = {sizeof(wc), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, wndproc, 0, 0, 0, LoadIcon(0, IDI_APPLICATION), LoadCursor(0, IDC_ARROW), (HBRUSH)1, "", "Hello", LoadIcon(0, IDI_APPLICATION)};
99
+ int main(){
100
+ RegisterClassEx(&wc);
101
+ HWND main = CreateWindowEx(0, "Hello", <%= context(title, :cstring) %>, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
102
+ <%= context(bound, :bound) %>,
103
+ 0, 0, 0, 0
104
+ );
105
+ <%= context(get('com.win32.buttons'), :app) %>
106
+ MSG msg;
107
+ while(GetMessage(&msg, 0, 0, 0) > 0){
108
+ DispatchMessage(&msg);
109
+ TranslateMessage(&msg);
110
+ }
111
+ }
data/test/test4.rb ADDED
@@ -0,0 +1,9 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+ require 'ua/uadb'
4
+ class My < Ua::Application
5
+ include Ua::SQLite3Support
6
+ end
7
+
8
+ x = My.new
9
+ p x
data/test/test5.rb ADDED
@@ -0,0 +1,142 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+ require 'win32api'
4
+ class Maker < Ua::Application
5
+ def initialize
6
+ super
7
+ add 'com.dll.a' do
8
+ %{
9
+ extern "C" <%= context(type.last, :app, []) %> __stdcall <%= context(funcname, :app) %>(<%= context(type.rhead, :app, args || (:a..:z).to_a) %>){
10
+ <%= context(fbody, :clang, type) %>
11
+ }
12
+ }
13
+ end
14
+
15
+ get('com.dll.a').prototype.class_eval do
16
+ def uacontext(a)
17
+ case a
18
+ when :compile
19
+ @dll ||= begin
20
+ self.name ||= Ua::Application.top_app.tmpid + ".cpp"
21
+ self.funcname ||= "func"
22
+ IO.binwrite self.name, context(self, :app)
23
+ self.dllname ||= self.name + ".dll"
24
+ system "g++ #{self.name} -o #{self.dllname} -static -s -shared -Wl,--add-stdcall-alias"
25
+ lambda{|*args|
26
+ Win32API.new(self.dllname, self.funcname, args.map{|x| Integer === x ? "L" : "p"}, "L").call(*args)
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+
37
+
38
+ class AlgeType
39
+ attr_accessor :type, :next
40
+ def initialize(type = nil)
41
+ @type = type
42
+ @next = nil
43
+ end
44
+ def detach
45
+ AlgeType.new(@type)
46
+ end
47
+
48
+ def >> rhs
49
+ x = AlgeType.new(@type)
50
+ case rhs
51
+ when AlgeType
52
+ x.next = rhs
53
+ else
54
+ x.next = AlgeType.new(rhs)
55
+ end
56
+ x
57
+ end
58
+
59
+ def * rhs
60
+ t = Array(@type).compact
61
+ d = if AlgeType === rhs then rhs else AlgeType.new(rhs) end
62
+ t += Array(d.type)
63
+ AlgeType.new t
64
+ end
65
+
66
+ def last
67
+ if self.next
68
+ self.next.last
69
+ else
70
+ self
71
+ end
72
+ end
73
+
74
+ def rhead
75
+ if self.next
76
+ self.detach >> self.next.rhead
77
+ else
78
+ nil
79
+ end
80
+ end
81
+
82
+ def coerce(rhs)
83
+ [AlgeType.new(rhs), self]
84
+ end
85
+
86
+ def cfunc(expr)
87
+ x = Ua::Application.top_app.create 'com.dll.a',
88
+ type: self,
89
+ fbody: expr
90
+ context(x, :compile)
91
+ end
92
+ end
93
+
94
+ def int() AlgeType.new([:int]) end
95
+ def unit() AlgeType.new([]) end
96
+
97
+ app = Maker.new
98
+ Ua::Application.push_app app
99
+ app.context AlgeType, :app do |atype, val|
100
+ ret = []
101
+ i = 0
102
+ while atype && atype.type
103
+ unless val.empty?
104
+ ret << [context(atype.type, :app).to_s << " " << context(val[i], :app).to_s]
105
+ else
106
+ ret << [context(atype.type, :app).to_s]
107
+ end
108
+ atype = atype.next
109
+ i += 1
110
+ end
111
+ ret.join(",")
112
+ end
113
+
114
+
115
+ class Expr
116
+ attr_accessor :atom
117
+ def initialize(atom)
118
+ @atom = "(" + atom.to_s + ")"
119
+ end
120
+ def +(rhs)
121
+ Expr.new(context(self, :expr) + "+" + context(rhs, :expr))
122
+ end
123
+ def uacontext(app, *a)
124
+ if app == :clang
125
+ return "return #{context(self, :expr)};"
126
+ elsif app == :expr
127
+ return @atom
128
+ end
129
+ throw :continue
130
+ end
131
+ end
132
+
133
+ def var(a)
134
+ Expr.new(a)
135
+ end
136
+
137
+ app.context Symbol, :app, &:to_s
138
+
139
+
140
+ r = (int.>> int.>> int).cfunc var(:a) + var(:b)
141
+ p r.call(3, 5)
142
+
data/ua.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ua/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ua"
8
+ spec.version = Ua::VERSION
9
+ spec.authors = ["Artoria"]
10
+ spec.email = ["Artoria"]
11
+ spec.summary = %q{ Unified App Generator }
12
+ spec.description = %q{ Unified App Generator }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ua
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Artoria
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: " Unified App Generator "
42
+ email:
43
+ - Artoria
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".settings/settings.json"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/missing/erb.rb
55
+ - lib/missing/ostruct.rb
56
+ - lib/ua.rb
57
+ - lib/ua/uadb.rb
58
+ - lib/ua/version.rb
59
+ - test/Hello.cpp
60
+ - test/a.db
61
+ - test/com.win32.cpp
62
+ - test/m.html
63
+ - test/temp.2.cpp
64
+ - test/temp.4.cpp
65
+ - test/test.js
66
+ - test/test.rb
67
+ - test/test2.rb
68
+ - test/test3.rb
69
+ - test/test4.rb
70
+ - test/test5.rb
71
+ - ua.gemspec
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Unified App Generator
96
+ test_files:
97
+ - test/Hello.cpp
98
+ - test/a.db
99
+ - test/com.win32.cpp
100
+ - test/m.html
101
+ - test/temp.2.cpp
102
+ - test/temp.4.cpp
103
+ - test/test.js
104
+ - test/test.rb
105
+ - test/test2.rb
106
+ - test/test3.rb
107
+ - test/test4.rb
108
+ - test/test5.rb