Skip to content

Commit

Permalink
Added WA binding for path, content, work_book, work_sheet. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 27, 2024
1 parent 9e45483 commit 3b05b28
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 38 deletions.
24 changes: 15 additions & 9 deletions Tools/RustWasmGen/gen.yue
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ basicTypes =
convertFrom: (name)-> "FromDoraString(#{name})"
convertTo: (name)-> "ToDoraString(#{name})"
argType: "string"
returnType: "*string"
returnType: "string"
creturn: (name, fnArgId)-> "#{name}, _ := stack#{fnArgId}.PopStr()"
cpass: (name, fnArgId)-> "stack#{fnArgId}.Push(#{name})"
}
Expand Down Expand Up @@ -394,7 +394,7 @@ basicTypes =
convertFrom: (name)-> name
convertTo: (name)-> name
argType: "DBParams"
returnType: "*DBParams"
returnType: "DBParams"
creturn: (name, fnArgId)-> "#{name}, _ := DBParamsFrom(stack#{fnArgId}.PopI64())"
cpass: -> error "unsupported"
}
Expand Down Expand Up @@ -437,8 +437,10 @@ basicTypes =
* (fnArgId)-> "crate::dora::WorkBook::from(stack#{fnArgId}.pop_i64().unwrap())"
* -> error "unsupported"
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
convertFrom: (name)-> "*WorkBookFrom(#{name})"
convertTo: (name)-> "#{name}.GetRaw()"
argType: "WorkBook"
returnType: "WorkBook"
}
WorkSheet:
* "i64"
Expand All @@ -451,8 +453,10 @@ basicTypes =
* (fnArgId)-> "crate::dora::WorkSheet::from(stack#{fnArgId}.pop_i64().unwrap())"
* -> error "unsupported"
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
convertFrom: (name)-> "*WorkSheetFrom(#{name})"
convertTo: (name)-> "#{name}.GetRaw()"
argType: "WorkSheet"
returnType: "WorkSheet"
}
VecStr:
* "i64"
Expand Down Expand Up @@ -1085,10 +1089,8 @@ func #{clsNewName}.GetType() => i32 {
func #{clsNewName}.GetRaw() => i64 {
return *this.raw
}
#wa:runtime_getter
func _get#{clsNewName}(ptr: u32) => i64
func #{finalizer}(ptr: u32) {
#{namespace}#{clsNewNameL}_release(_get#{clsNewName}(ptr))
#{namespace}#{clsNewNameL}_release(GetPtr(ptr))
}
func #{clsNewName}From(raw: i64) => *#{clsNewName} {
if raw == 0 {
Expand Down Expand Up @@ -1722,6 +1724,10 @@ func #{clsNewName}From(raw: i64) => *#{clsNewName} {
"rect"
"texture_2d"
"ease"
"path"
"content"
"work_book"
"work_sheet"
]
\write "\n"
\write table.concat waBinding, "\n"
Expand Down
4 changes: 1 addition & 3 deletions Tools/dora-wa/vendor/dora/action_def.wa
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ type ActionDef struct { raw: *i64 }
func ActionDef.GetRaw() => i64 {
return *this.raw
}
#wa:runtime_getter
func _getActionDef(ptr: u32) => i64
func action_def_finalizer(ptr: u32) {
actiondef_release(_getActionDef(ptr))
actiondef_release(GetPtr(ptr))
}
func ActionDefFrom(raw: i64) => *ActionDef {
if raw == 0 {
Expand Down
8 changes: 4 additions & 4 deletions Tools/dora-wa/vendor/dora/app.wa
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ func _App.GetVisualSize() => Size {
func _App.GetDevicePixelRatio() => f32 {
return application_get_device_pixel_ratio()
}
func _App.GetPlatform() => *string {
func _App.GetPlatform() => string {
return FromDoraString(application_get_platform())
}
func _App.GetVersion() => *string {
func _App.GetVersion() => string {
return FromDoraString(application_get_version())
}
func _App.GetDeps() => *string {
func _App.GetDeps() => string {
return FromDoraString(application_get_deps())
}
func _App.GetDeltaTime() => f64 {
Expand All @@ -123,7 +123,7 @@ func _App.IsDebugging() => bool {
func _App.SetLocale(val: string) {
application_set_locale(ToDoraString(val))
}
func _App.GetLocale() => *string {
func _App.GetLocale() => string {
return FromDoraString(application_get_locale())
}
func _App.SetThemeColor(val: Color) {
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-wa/vendor/dora/camera.wa
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ func CameraFrom(raw: i64) => *Camera {
func Camera.GetType() => i32 {
return camera_type()
}
func Camera.GetName() => *string {
func Camera.GetName() => string {
return FromDoraString(camera_get_name(*this.raw))
}
119 changes: 118 additions & 1 deletion Tools/dora-wa/vendor/dora/content.wa
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,121 @@ func content_zip_async(folder_path: i64, zip_file: i64, func0: i32, stack0: i64,
#wa:import dora content_unzip_async
func content_unzip_async(zip_file: i64, folder_path: i64, func0: i32, stack0: i64, func1: i32, stack1: i64)
#wa:import dora content_load_excel
func content_load_excel(filename: i64) => i64
func content_load_excel(filename: i64) => i64
type _Content struct { }
global Content = _Content{}
func _Content.SetSearchPaths(val: *[]string) {
content_set_search_paths(ToDoraStrBuf(val))
}
func _Content.GetSearchPaths() => *[]string {
return FromDoraStrBuf(content_get_search_paths())
}
func _Content.GetAssetPath() => string {
return FromDoraString(content_get_asset_path())
}
func _Content.GetWritablePath() => string {
return FromDoraString(content_get_writable_path())
}
func _Content.Save(filename: string, content: string) => bool {
return content_save(ToDoraString(filename), ToDoraString(content)) != 0
}
func _Content.Exist(filename: string) => bool {
return content_exist(ToDoraString(filename)) != 0
}
func _Content.Mkdir(path: string) => bool {
return content_mkdir(ToDoraString(path)) != 0
}
func _Content.Isdir(path: string) => bool {
return content_isdir(ToDoraString(path)) != 0
}
func _Content.IsAbsolutePath(path: string) => bool {
return content_is_absolute_path(ToDoraString(path)) != 0
}
func _Content.Copy(src: string, dst: string) => bool {
return content_copy(ToDoraString(src), ToDoraString(dst)) != 0
}
func _Content.MoveTo(src: string, dst: string) => bool {
return content_move_to(ToDoraString(src), ToDoraString(dst)) != 0
}
func _Content.Remove(path: string) => bool {
return content_remove(ToDoraString(path)) != 0
}
func _Content.GetFullPath(filename: string) => string {
return FromDoraString(content_get_full_path(ToDoraString(filename)))
}
func _Content.AddSearchPath(path: string) {
content_add_search_path(ToDoraString(path))
}
func _Content.InsertSearchPath(index: i32, path: string) {
content_insert_search_path(index, ToDoraString(path))
}
func _Content.RemoveSearchPath(path: string) {
content_remove_search_path(ToDoraString(path))
}
func _Content.ClearPathCache() {
content_clear_path_cache()
}
func _Content.GetDirs(path: string) => *[]string {
return FromDoraStrBuf(content_get_dirs(ToDoraString(path)))
}
func _Content.GetFiles(path: string) => *[]string {
return FromDoraStrBuf(content_get_files(ToDoraString(path)))
}
func _Content.GetAllFiles(path: string) => *[]string {
return FromDoraStrBuf(content_get_all_files(ToDoraString(path)))
}
func _Content.LoadAsync(filename: string, callback: func(content: string)) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
content, _ := stack0.PopStr()
callback(content)
})
content_load_async(ToDoraString(filename), func_id0, *stack0.raw)
}
func _Content.CopyAsync(src_file: string, target_file: string, callback: func(success: bool)) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
success, _ := stack0.PopBool()
callback(success)
})
content_copy_async(ToDoraString(src_file), ToDoraString(target_file), func_id0, *stack0.raw)
}
func _Content.SaveAsync(filename: string, content: string, callback: func(success: bool)) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
success, _ := stack0.PopBool()
callback(success)
})
content_save_async(ToDoraString(filename), ToDoraString(content), func_id0, *stack0.raw)
}
func _Content.ZipAsync(folder_path: string, zip_file: string, filter: func(file: string) => bool, callback: func(success: bool)) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
file, _ := stack0.PopStr()
result_ := filter(file)
stack0.Push(result_)
})
stack1 := NewCallStack()
func_id1 := PushFunction(func() {
success, _ := stack1.PopBool()
callback(success)
})
content_zip_async(ToDoraString(folder_path), ToDoraString(zip_file), func_id0, *stack0.raw, func_id1, *stack1.raw)
}
func _Content.UnzipAsync(zip_file: string, folder_path: string, filter: func(file: string) => bool, callback: func(success: bool)) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
file, _ := stack0.PopStr()
result_ := filter(file)
stack0.Push(result_)
})
stack1 := NewCallStack()
func_id1 := PushFunction(func() {
success, _ := stack1.PopBool()
callback(success)
})
content_unzip_async(ToDoraString(zip_file), ToDoraString(folder_path), func_id0, *stack0.raw, func_id1, *stack1.raw)
}
func _Content.LoadExcel(filename: string) => WorkBook {
return *WorkBookFrom(content_load_excel(ToDoraString(filename)))
}
25 changes: 12 additions & 13 deletions Tools/dora-wa/vendor/dora/dora.wa
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ func ToDoraString(str: string) => i64 {
return ptr
}

func FromDoraString(str: i64) => *string {
func FromDoraString(str: i64) => string {
length := str_len(str)
buf := make([]byte, length)
str_read_ptr(waBytesToPtr(buf), str)
result := string(buf)
return &result
return string(buf)
}

/* bool */
Expand Down Expand Up @@ -187,7 +186,7 @@ func FromDoraStrBuf(v: i64) => *[]string {
buf_read_ptr(waI64SliceToPtr(buf), v)
strs := make([]string, length)
for i := 0; i < int(length); i++ {
strs[i] = *FromDoraString(buf[i])
strs[i] = FromDoraString(buf[i])
}
return &strs
}
Expand Down Expand Up @@ -252,10 +251,10 @@ func Object.GetRaw() => i64 {
}

#wa:runtime_getter
func _getObjectPtr(ptr: u32) => i64
func GetPtr(ptr: u32) => i64

func ObjectFinalizer(ptr: u32) {
object_release(_getObjectPtr(ptr))
object_release(GetPtr(ptr))
}

func createObject(raw: i64) => Object {
Expand Down Expand Up @@ -364,9 +363,9 @@ func Value.GetF64() => (f64, bool) {
return value_into_f64(*this.raw), true
}

func Value.GetStr() => (*string, bool) {
func Value.GetStr() => (string, bool) {
if value_is_str(*this.raw) == 0 {
return nil, false
return "", false
}
return FromDoraString(value_into_str(*this.raw)), true
}
Expand Down Expand Up @@ -401,7 +400,7 @@ func Value.GetSize() => (Size, bool) {
}

func value_finalizer(ptr: u32) {
value_release(_getObjectPtr(ptr))
value_release(GetPtr(ptr))
}

func ValueFrom(ptr: i64) => Value {
Expand Down Expand Up @@ -552,7 +551,7 @@ func CallStack.GetRaw() => i64 {
}

func call_stack_finalizer(ptr: u32) {
call_stack_release(_getObjectPtr(ptr))
call_stack_release(GetPtr(ptr))
}

func NewCallStack() => CallStack {
Expand Down Expand Up @@ -631,9 +630,9 @@ func CallStack.PopF64() => (f64, bool) {
return call_stack_pop_f64(*this.raw), true
}

func CallStack.PopStr() => (*string, bool) {
func CallStack.PopStr() => (string, bool) {
if call_stack_front_str(*this.raw) == 0 {
return nil, false
return "", false
}
return FromDoraString(call_stack_pop_str(*this.raw)), true
}
Expand Down Expand Up @@ -724,7 +723,7 @@ func Println(values: ...interface{}) {
if !ok {
value, ok := v.GetStr()
if ok {
strs[i] = *value
strs[i] = value
}
}
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-wa/vendor/dora/node.wa
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func Node.GetSize() => Size {
func Node.SetTag(val: string) {
node_set_tag(*this.raw, ToDoraString(val))
}
func Node.GetTag() => *string {
func Node.GetTag() => string {
return FromDoraString(node_get_tag(*this.raw))
}
func Node.SetOpacity(val: f32) {
Expand Down
28 changes: 27 additions & 1 deletion Tools/dora-wa/vendor/dora/path.wa
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,30 @@ func path_replace_ext(path: i64, new_ext: i64) => i64
#wa:import dora path_replace_filename
func path_replace_filename(path: i64, new_file: i64) => i64
#wa:import dora path_concat
func path_concat(paths: i64) => i64
func path_concat(paths: i64) => i64
type _Path struct { }
global Path = _Path{}
func _Path.GetExt(path: string) => string {
return FromDoraString(path_get_ext(ToDoraString(path)))
}
func _Path.GetPath(path: string) => string {
return FromDoraString(path_get_path(ToDoraString(path)))
}
func _Path.GetName(path: string) => string {
return FromDoraString(path_get_name(ToDoraString(path)))
}
func _Path.GetFilename(path: string) => string {
return FromDoraString(path_get_filename(ToDoraString(path)))
}
func _Path.GetRelative(path: string, target: string) => string {
return FromDoraString(path_get_relative(ToDoraString(path), ToDoraString(target)))
}
func _Path.ReplaceExt(path: string, new_ext: string) => string {
return FromDoraString(path_replace_ext(ToDoraString(path), ToDoraString(new_ext)))
}
func _Path.ReplaceFilename(path: string, new_file: string) => string {
return FromDoraString(path_replace_filename(ToDoraString(path), ToDoraString(new_file)))
}
func _Path.Concat(paths: *[]string) => string {
return FromDoraString(path_concat(ToDoraStrBuf(paths)))
}
4 changes: 1 addition & 3 deletions Tools/dora-wa/vendor/dora/rect.wa
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ type Rect struct { raw: *i64 }
func Rect.GetRaw() => i64 {
return *this.raw
}
#wa:runtime_getter
func _getRect(ptr: u32) => i64
func rect_finalizer(ptr: u32) {
rect_release(_getRect(ptr))
rect_release(GetPtr(ptr))
}
func RectFrom(raw: i64) => *Rect {
if raw == 0 {
Expand Down
Loading

0 comments on commit 3b05b28

Please sign in to comment.