Forum Replies Created
- 
		AuthorPosts
 - 
		
			
				
I’ll assume that’s a no, then.
isn’t that what Lambda() and End are for?
Pretty much, but the majority of the Monkey-X/MX2 community have an aversion to braces.
How hard would it be to tell the parser to make newlines optional for single statement lambdas, then? That should be a simple enough change, and if the developer prefers to split it across multiple lines, that’s up to them.
TBH, I find this unreadable… If you want to return something, why not state it?
The idea is less about the implicit return statement and more about keeping a simple lambda on a single line.
With a return statement and no inferred types it’s still quite legible. It just makes it much cleaner if you want to pass a single expression as a parameter to a function.[/crayon]Monkey123456[crayon-5cb9e3bad1682251358076 inline="true" ]' Single line:SomeMethod(Lambda:Int(x:Int) Return x + 1 End)' As opposed to:SomeMethod(Lambda:Int(x:Int)Return x + 1End)Maybe it’ll grow on me (it has a tiny bit) but right now I just don’t see the need for it.
If I add flatmap/filter/reduce to the Stack class and provide an example banana project, you’ll see the power of mini-closures and why it makes code much easier to understand. I’ve already added it, I’ll make a PR at some point.
Sorry, I’m not quite clear on your response. Was that “accept the pull request” or “accept the existing syntax”?
One of the more powerful uses of lambdas/closures is to represent a very simple piece of logic (even one expression) as a first-class type. If the lambda in question is as simple as a comparison or equation, I think the condensed one-line syntax is quite acceptable.
If the lambda has a lot of logic to it (event handlers, etc.) then it makes sense to spread it across as many lines as you need, as per the current syntax.I’ll be honest here, I’m trying to add some lambda stuff to bbArray. Since there are no extensions/categories (yet), it’s going to have to be externed and a PR into the core std library.
[/crayon]Monkey12345[crayon-5cb9e3bad848b890034112 inline="true" ]Local foo:Int[] = New Int[](1, 2, 3, 4, 5)Local bar:String[] = foo.FlatMap(Lambda:String(value:Int)Return "This is value " + valueEnd)' gives string array ["This is value 1", ...]And so on.
Imo plugins in Lua. Then you can re-use existing libraries. Actually, I might even write a plugin that will execute Lua in the editor.
Thanks, I might have to look at hacking in some reflection myself.
I uploaded mx2lua a while ago and and it hasn’t been reviewed yet. :'(
Version 0.1.0 tag added and uploaded for review.
http://monkey2.monkey-x.com/forums/topic/experimental-module-manager-now-online/page/2/#post-2471Lua module v0.1.0 uploaded. Still major WIP, but it’s usable.
I’d love to see what people can do with the current build so that I know the best direction to take the project.
Reeaalllyyy hoping for reflection soon so I can make the field and method bindings automatic and transparent to the developer.Singular makes sense to me, as it’s an identifier to a single asset. Kinda like the “file://” URI prefix. I would recommend against allowing both singular and plural. Just pick one and stick with it.
Just wait until mx2lua is a bit more mature. Then you can go mental with the coroutines.
Worked a bit more on the class binding. At the moment you still need to know how to do some low level stuff, but I hope to make this cleaner in the future.
I added a very simple Mojo demo, too. It has a placeholder for “script reloading”, but you’ll need to change it to DoFile and make sure the Lua file is in the right place. Whenever I test it from my build script, it tries to look in the root monkey2 directory rather than the current directory.
I’d love to see some of your usage examples so that I know how to make it betterer! Note: Coroutines are much nicer for handling entity logic, rather than constantly calling DoString as in my example.
Fixed. Stupid git (not you).
git rm --cached native/luadistI’m working on a simple Mojo demo project at the moment, hopefully with a “reload script” shortcut. At the moment you’re mostly limited to calling MX2 functions that you declare yourself, so it’s still WIP for usefulness. Coming along, though!
Reloading scripts will need to use DoFile rather than DoString(LoadString), as I believe the assets get baked into the distribution.
Note when using DoString/DoFile/PCall, make sure to wrap it with an if statement and grab the string value at the top of the stack. If there was an error somewhere in your script, that error message will be on the stack. You can also give custom error messages in your MX2 registered functions using state.Error/ lua_error. This will push the error message and raise an exception that’s caught by the Lua VM. Note that this call does a long jump and never returns.
 - 
		AuthorPosts