Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea 3.5 version (316)

dave1707dave1707 Mod
edited December 2021 in Bugs Posts: 9,808

@Simeon Not sure how long this has been happening, but when I tap on Do, then Assets I get the list of Assets.Tap the Project asset for that list. Tap the + on the Text line and create a new text file. Give it a name a tap Create. That file shows under Text. Tap on the pencil icon on the new text file. Nothing happens. To edit the text file, I have to add the line readText() in the project and then tap between the () to get to the list of files. From there I can tap the pencil icon to edit the file.

Comments

  • edited December 2021 Posts: 239

    sort of related but i get a problem where the bottom panel covers the buttons on the bottom of the assets view

  • Posts: 2,574

    @Simeon - just loaded up 3.5 and tried to run CraftSceneInator() from @UberGoober. First thing I find 3.5 a little slow, and with CraftSceneInator() it throws up an initial error relating to the assert() command which carries a parameter in addition to the comment. Followed by an error relating to no Craft.scene available. Commenting out the assert line runs the code correctly. Also after restarting the Codea the speed of operation had increased and was smoother.

  • Posts: 2,574

    @Simeon - just loaded up WebRepo and crashed, sent a report. Re-ran after rebooting error attached as image.

  • SimeonSimeon Admin Mod
    Posts: 5,759

    @skar thanks for finding that!

    @dave1707 hmm good find, will look into it

    @Bri_G thank you for sending the report, 3.5 should be the same as 3.4.7 in terms of performance but I'll keep an eye out

  • SimeonSimeon Admin Mod
    edited December 2021 Posts: 5,759

    In build 316 there's a new feature by @jfperusse that I'm pretty excited about

    He added Lua bindings to the native iOS SDK, so you can access most APIs through objc in Lua

    This means you can write your own support for game controllers, for example:

    function setup()
        local controllers = objc.cls.GCController.controllers
        local count = #controllers
    
        if count > 0 then
            controller = controllers[1]
            gamepad = controller.extendedGamepad
            dpad = gamepad.dpad
    
            dpad.left.pressedChangedHandler = function(objButton, floatValue, boolPressed)
                -- Note the prefixes on the argument names
                -- these are necessary to tell the system how to map types into Lua
                print("left changed " .. boolPressed and "pressed" or "released")
            end
    
            print(math.floor(controller.battery.batteryLevel * 100) .. "%")
        end
    end
    

    Or you could make use of NSURLSession (and web sockets), send local notifications, there are thousands of APIs exposed through this feature.

    These are documented here (use the Objective-C documentation where possible)

    https://developer.apple.com/documentation/technologies

    Only iOS frameworks are applicable, and not all frameworks are included yet, so if you have a request, let us know

    Some frameworks will be inaccessible due to entitlements (CloudKit), and Swift-only frameworks can't be bound automatically

  • Posts: 327

    @Simeon, That’s fantastic! I’ll certainly be taking a look into that.

  • dave1707dave1707 Mod
    Posts: 9,808

    @Simeon or anyone. Is the above code supposed to run on the iPad (or just a Mac) or is something else supposed to be included. count is 0 when I run it. Never did anything with Objective-C so I don’t know.

  • Hi @dave1707! Is your controller properly connected to your iPad? If so, please try simply launching your project again. I noticed that the controllers list is empty the very first time it is accessed. In my projects, I check the list again in draw() if I couldn't find a controller yet. It should also be possible to use startWirelessControllerDiscoveryWithCompletionHandler but I have yet to try it out.

  • dave1707dave1707 Mod
    Posts: 9,808

    @jfperusse I guess that’s my problem, a controller. Nothing is connected to my iPad. I just write code to past the time, nothing major. So it will take awhile to figure out what can be done with the Objective-C stuff. I guess I’ll just wait for others to post examples.

  • edited December 2021 Posts: 47

    @dave1707 At least that explains the count being 0 :smile:

    If you want to try a simpler example, you can change your ipad brightness like so:

    objc.cls.UIScreen.mainScreen.brightness = 0.5 -- a value between 0.0 and 1.0

    Though I'm not sure what kind of game could use this as a feature :lol:

  • dave1707dave1707 Mod
    Posts: 9,808

    So here’s a simple example using the above code. Move the slider for a brightness value and tap the screen to apply it.

    Just have to figure out where to find a simple list all the objc stuff.

    viewer.mode=STANDARD
    
    function setup()
        fill(255)
        parameter.number("bright",.2,.8,.5)
        brightness=objc.cls.UIScreen.mainScreen.brightness
    end
    
    function draw()
        background(0)
        text(brightness,WIDTH/2,HEIGHT/2)
    end
    
    function touched(t)
        if t.state==BEGAN then
            objc.cls.UIScreen.mainScreen.brightness=bright
        elseif t.state==ENDED then
            brightness=objc.cls.UIScreen.mainScreen.brightness
        end
    end
    
  • edited December 2021 Posts: 1,629
    Holy shamoley the objc bindings are so exciting!

    This crashes my iPhone:

    ~~~

    uiVC = objc.cls.UIViewController()
    rootVC = objc.cls.UIApplication:sharedApplication().keyWindow.rootViewController
    rootVC:presentViewController_animated_completion_(uiVC, false, nil)

    ~~~
  • edited December 2021 Posts: 1,629
    Sorry for the momentary double-post, I was trying to get around the bug where code doesn’t format correctly when you enter a post on the iPhone.
  • Hey @UberGoober! Thanks for testing out the feature :smile:

    I'll see why the above code crashes and keep you updated.

  • Posts: 1,629

    @jfperusse the final line should probably be: rootVC.presentedViewController.presentedViewController:presentViewController_animated_completion_(uiVC, false, nil) (which still crashes)

    Because presenting from the rootVC shouldn’t work anyway.

  • edited December 2021 Posts: 1,629

    Is there a way to access objective-C global enums?

    For example UIModalPresentationStyle?

  • edited December 2021 Posts: 47

    There is no way at the moment to access global methods and enums as the C language does not have this level of runtime reflection. However, we think we might later be able to parse the different framework headers and expose those through new properties such as objc.global.UIModalPresentationStyle.UIModalPresentationAutomatic.

    I'll be looking into this for a future update :wink:

  • @UberGoober I confirm that I can reproduce your crash. I'll see if we can at least prevent the runtime from crashing, and also investigate what's wrong with the call.

  • Posts: 1,629

    @jfperusse thanks, and thanks for all this, it’s great.

    Enums are particularly needed because some classes can’t be instantiated without them.

  • @UberGoober Even if you don't have access to the enums, you can use or combine their integer values instead. See the third example in the documentation for objc.cls where I'm combining three enum values.
  • My app crashes consistently when returning to the editor after running ok-no idea why? Sent a crash log.

  • @piinthesky Are you using the new objc feature?
  • No, just my previously working code.

  • edited December 2021 Posts: 2,574

    @dave1707 - couldn’t see you code working. Tried modifying to the code below but brightness didn’t seem to change ?. Do we need to init the calls in some way ?


    viewer.mode=STANDARD function setup() fill(255) parameter.number("bright",.2,.8,.5) brightness=objc.cls.UIScreen.mainScreen.brightness end function draw() background(255, 0, 230) text(bright,WIDTH/2,HEIGHT/2) end function touched(t) if t.state==BEGAN then objc.cls.UIScreen.mainScreen.brightness=bright elseif t.state==ENDED then bright=objc.cls.UIScreen.mainScreen.brightness end end
  • edited December 2021 Posts: 2,574

    All,

    Had a funny recently on the forum. When I have created a new post and tapped post comment it seemed to hang up, a second tap on post comment shifted to a blank page with a new blank editing box at the top. Anyone else seen this?

    p.s. that's on my iPad.

  • dave1707dave1707 Mod
    edited December 2021 Posts: 9,808

    @Bri_G I loaded your version and when I changed the slider and tapped the screen, I could see the screen brighten or darken depending on the slider value.

  • Posts: 2,574
    @dave1707 - doh, forgot to tap the screen. Naively thinking changing the slider would respond the same. Thanks for the post.
  • @UberGoober I found at least two issues in our objc implementation which I'll be fixing shortly. In the meantime, you can try the following code:

        local uiView = objc.cls.UIViewController()
        local application = objc.cls.UIApplication:sharedApplication()
        local window = application.keyWindow;
        local root = window.rootViewController;
        local presented = root.presentedViewController.presentedViewController;    
        presented:presentViewController_animated_completion_(uiView, false, function() end)
    end
    
  • SimeonSimeon Admin Mod
    Posts: 5,759

    @piinthesky I just checked out the logs, there is no crash stack which makes me concerned. Is it caused by a project small enough to share that we can use to reproduce?

  • Posts: 1,629

    @jfperusse oh right, duh, enums are just ints. Thanks for reminding me.

  • @UberGoober Finally managed to add a dynamically created UIView. Had to do various fixes so this will only be possible in the next beta version.

    The new beta will also include a fix to prevent crashes when invoking a method with the wrong type of arguments, as well as some validation and error messages.

    Here's the code I've been able to use on my iPad after the fixes:

        local view = objc.cls.UIView:alloc():initWithFrame_(objc.rect(100, 100, 100, 100))
        view.backgroundColor = objc.cls.UIColor:redColor()
        local application = objc.cls.UIApplication:sharedApplication()
        local root = application.keyWindow.rootViewController
        root.presentedViewController.presentedViewController.view:addSubview_(view)
    
    IMG_2232.PNG 190.2K
  • edited December 2021 Posts: 239

    @jfperusse i think the callback docs need fixing because it says to use prefixes like o for objects and b for bools but the example shows “objError” and “boolGranted”

    also the classes that we can use should be listed somewhere, i already tried a couple that don’t exist, and using “UIScreen” for an example is confusing since there is no reference or search results for UIScreen in the technologies page of apple, you have to dig down to UIKit and then click Windows and Screens to find it

    also, why not just remove underscores completely from the methods?

  • @Simeon its my large km3net app, which is quite complicated! What would be the best way to share it with you?
  • dave1707dave1707 Mod
    edited December 2021 Posts: 9,808

    @piinthesky Would you be able to post the zip file here. I could try it to see if I get the same results on different iPads.

  • SimeonSimeon Admin Mod
    Posts: 5,759

    @skar that's my fault, the docs are correct (you only need a single character) but I prefer the readability of writing a short word that begins with that character (o = obj, b = bool, etc)

    On methods with underscores, in Objective-C the colons (:) are part of the method name. So setSpeed:withObject: takes two arguments, and is distinct from the method named setSpeedwithObject (no arguments). In order to represent this in Lua @jfperusse maps the colons to underscores

    @piinthesky you could email me (simeon@twolivesleft.com) and share it as a zip or iCloud link. If it has dependencies then I'd need to use those too

  • Hi @skar! Sorry for the confusion in argument names. As Simeon mentioned, we went for an hybrid method where only the first 1 or 2 characters are really important, so you can choose between "oError" or "objError" based on your personnal preference. I could add a "Naming Convention" section to the documentation explaining that both options are possible.

    As for listing all possible classes, there would be too many, you do need to know what you're trying to implement, but we could actually list the included frameworks (UIKit, Game Controller, User Notification, etc.).
  • edited December 2021 Posts: 1,629

    @jfperusse that code works a treat! This is so cool.

    Also much thanks for the improved error handling.

    The very first thing I thought of when I saw this was how I’ve wanted a gui to save and load files since forever, so after I got your example working I immediately tried to implement a document picker:


    --[[ ***Objective-C example I found: ** Create the array of UTI Type that you want to support * Pass the array of UTI Type that application wants to support. Add more UTI Type if you want to support more other than listed */ —(According to the Swift example below it should be possible to simply use [“public.text”] here too) NSArray *types = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeSpreadsheet,(NSString*)kUTTypePresentation,(NSString*)kUTTypeDatabase,(NSString*)kUTTypeFolder,(NSString*)kUTTypeZipArchive,(NSString*)kUTTypeVideo]; //Create a object of document picker view and set the mode to Import UIDocumentPickerViewController *docPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeImport]; //Set the delegate docPicker.delegate = self; ***Swift example I found: UIDocumentPickerViewController(documentTypes: ["public.text"], inMode: UIDocumentPickerMode.Import) documentPicker.delegate = self ]] local application = objc.cls.UIApplication:sharedApplication() local window = application.keyWindow; local root = window.rootViewController; local presented = root.presentedViewController.presentedViewController; local picker = objc.cls.UIDocumentPickerViewController_initWithDocumentTypes_inMode_({"public.text"}, 0) picker.delegate = presented presented:presentViewController_animated_completion_(picker, false, function() end)

    …needless to say, it didn’t work. I’m not sure if instantiating a C array for a parameter is possible, for one thing, but the initialization call itself doesn’t seem to be right either.

    Is this possible?

  • @UberGoober You almost got it right! Try this:

        local application = objc.cls.UIApplication:sharedApplication()
        local window = application.keyWindow;
        local root = window.rootViewController;
        local presented = root.presentedViewController.presentedViewController; 
        local picker = objc.cls.UIDocumentPickerViewController:alloc()
        picker:initWithDocumentTypes_inMode_({"public.text"}, 0) 
        picker.delegate = presented
        presented:presentViewController_animated_completion_(picker, false, function() end)
    
  • Posts: 1,629

    OMG it works. I can see no further use for sliced bread!!

    Okay so I would never have been able to figure this out on my own without two crucial pieces of information that imho need to be in the documentation:

    • the pattern for typing multiple parameter names—I did figure this out myself through a lot of trial and error, eventually, but I already have some objc experience, so I think an example in the docs is really needed
    • the alloc pattern for accessing complex initializers. Imho this is really necessary to include as an example, because so many classes require it.
  • Posts: 1,629

    Fyi I just learned that the init syntax I used has been deprecated.

    This is the current way to do it:


    picker:initForOpeningContentTypes_({objc.cls.text})

    …and it works, yay.

  • Posts: 1,303

    This seems very cool. Where are you folks learning how to use this stuff? We're gonna need lots of little examples.

  • Posts: 1,629

    @RonJeffries this requires some understanding of objective-c and the native iOS APIs. I too look forward to lots of cool little helper classes coming from this.

  • Posts: 658

    @Simeon in version 320 i don't crash returning to editor!

  • SimeonSimeon Admin Mod
    Posts: 5,759

    @piinthesky odd as I didn't fix anything in that build! But I did find the issue on my side when running your test project, and I was able to fix it more thoroughly for the next build

Sign In or Register to comment.