Scripting Language extensions via plugins

Ah, I didn’t realize that!
I have rather long build times so just to be on the safe side I defined it as well :slight_smile:

Great news!

Also, I’ve read the source for your plugins over and over, but I can’t seem to figure out why some wrappers are not created,
for instance, StaticMesh.script.h is never generated, but StaticMeshComponent and StaticMeshActor are generated.
Same goes for ParticleSystem and some other important classes.

In your sample script at the opening-post you mentioned StaticMesh.Class(), I can’t replicate that because I don’t have the wrapper, hm.
Do you have any idea as for why that is?

And thanks again for putting time into this amazing plugin !

Yeah, sorry for the confusion, that example comes from one of the WIP versions of the plugin. When I was tidying it up, I changed a few things related to what gets exported. Basically there’s three functions that control what gets exported: CanExportFunction, CanExportProperty and CanExportClass. The last one uses (or used in this particular case) the former two to determine if it’s actually worth to export the class (i.e. does it have anything to export). So to export more stuff, you’d probably need to change the Lua code generator’s CanExportClass to look like FGenericScriptCodeGenerator::CanExportClass (which also checks for properties to export) and add an override for CanExportProperty which accepts all properties which are editable, like so:


bool FLuaScriptCodeGenerator::CanExportProperty(const FString& ClassNameCPP, UClass* Class, UProperty* Property)
{
	// Only public, editable properties can be exported
	if (!(Property->PropertyFlags & CPF_Edit))
	{
		return false;
	}

	// Reject if it's one of the unsupported types (yet)
	...


Thanks a lot once again Robert !
EDIT:

One thing I have been struggling with all night and day is that after I rebuilt the engine, my projects no longer generate .generated.inl files.
All I’m trying to do is:

  1. make a new basic code project
  2. build it
    But I always end up with a fatal error, “cannot find include file .generated.inl”.

Sorry, I’m very new to all of this, I don’t even know when/how those files are generated so I can’t seem to debug the issue…

Yeah, we no longer generate *.inl files. We now do *.generated.cpp files which are automatically compiled by UBT, so you no longer need to include the inl manually. Since the Github source does not contain Template folder (so your generated project uses the old template) you need to remove the *.generated.inl include from the project manually. We’ll update the template folder with the next release.

Thanks for your time :slight_smile: much appreciated.

Just out of genuine curiosity, is there going to be any further expansion on the Lua integration in terms of new bindings in order to increase functionality? I understand that you’re going to organize a blog post or something similar to that in the near future? Because I would really like to actually know what I can, and cannot call and with what arguments because at the moment I can’t get any sort of method to retrieve arguments working at the moment, just the function names themselves (which is pretty easy to do) but I have yet to call a function successfully (guessing the arguments) without causing UE4 to completely crash out on me.

I really look forward to having Lua integration in Unreal Engine 4 hence why I am posting this rather than lurking around in the background as per usual. The plugin is extremely promising and I’m happy that it was integrated but I feel like no actual work can be done with it in terms of adding actual gameplay elements, which is obviously to be expected at this point in time, I’m just more or less just curious about the future of the plugin.

Thanks~

Yeah, I checked something in today (here). So now it exports all UFUNCTIONS and all editable properties (decorated with accessor functions, for example: Set_StaticMesh, Get_StaticMesh) unless a function (or property) uses unsupported type (only a few Core structures like FVector, FVector4, FTransform are supported for example; FNames and FText are treated just like strings on Lua side). You will notice it exports MOST of the engine classes now (basically only those that have no editable properties nor UFUNCTIONs are not exported).

If you want to know what parameters functions have, all you need to do is to look up the respective UFUNCTION declaration in the engine code.

Thank you very much!

This is brilliant! It’s great to see progress on the project, I’m falling it love with it the more I use it, hehe :smiley:
Adding FVector2D and FColor would be useful too, especially for HUD related stuff like DrawText etc.

I modified the ScriptComponent to include some blueprint nodes for calling LUA functions and to get/set global variables.
It works like a charm, but I’m not entirely sure how I’d go about exposing function parameters to blueprint nodes,
I guess I’d need to extend a K2Node for more blueprint functionality?

Anyway, I’m really grateful for your dedication to this script plugin :wink:

Sure, I’ll add the other common structs this week. I was also thinking about TArray support.

Is it something you could share via pull request?

I’ll look into that BP functionality.

I’ve made the pull request now,
it’s not much, but gets the job done.

I was hoping for something like a single blueprint node and being able to select the type of variable in the editor,
but I’m uncertain about the best approach to achieve that.

Have a look at the Math expression plugin. Basically you create a class inheriting from UK2Node_Composite. At least that is how I did a script node when I played around with adding a Java script interpreter.

https://forums.unrealengine.com/showthread.php?1753-Simple-JavaScript-Scripting-interpreter-embedded-in-BluePrint

(see video in my last post in there for how the “Script Node” works).

Inside the composite, it calls functions to set the required variables and then executes the script. So if you define a variable named “Message” of type string in the details window, then a blueprint node calling a “Set String variable” function would be added automatically inside the composite node (with the set variable function/node taking a variable name and variable value as input), before the call to actually execute the script. If the user then changed that type to say bool, then the “set string variable” node would be deleted and a “set bool” one added. The user won’t see any of this unless they open up the Script node.

I will try to find some time to clean up and post the code for my node, if you want. However I’m a bit short of time at the moment so not sure when I will get a .

Hey, just wanted to give an update of where things are with the plugin.

So I integrated real’s changes but I haven’t checked them in yet. I’m currently working on a few things related to the plugin and I’m going to check it all in when I’m done.

We also had a discussion internally that it would be great to have something like the math expression plugin for Lua so it’s something I’m also going to be looking at.

I know I promised a blog post about the plugin this week. I’m not sure if I should do it though. There’s a few cool things I’m currently working on I’d like to include there but I doubt they’re going to be ready for tomorrow. Maybe I’ll split the blog post into two parts: generator and runtime.

And here’s a little sneak-peek of things to come:



Health = 0
Speed = 0
IsAlive = false
Name = ""

function BeginPlay()
...


is now going to give you:

LuaProperties.jpg

I hate to be That Guy, but…

Unreal Engine is not “open source”. Open source means the source code is freely available and generally implies that the license is (or would be) approved by the Open Source Initiative. Since you have to pay to get Unreal Engine’s source code, and you’re not allowed to redistribute that source code, it isn’t freely available.

I wish I could say what the correct term is, but I’m not sure there is one. Microsoft has the term “shared source”, but that term is only used in reference to MS’s licenses.

But yes, this is still very nice stuff indeed.

This is very interesting! One thing I want to know is what is the best way to access the bindings without using ScriptComponent
I would like to use this plugin to handle generating the bindings to everything, and getting those into Lua, but I want to have a bit more control over the lua state.

You see, I will be loading scripts at runtime into a lua_State, then pulling functions and running them as coroutines. I want the benefits of not having to generate bindings for all of the UE4 functions I want to call from Lua, without necessarily being locked into the workflow you have provided.

I will definitely write an article on this if I can get it to work for what I have intended, this is the missing link for many people wanting something like UnrealScript just for familiarity.

You could just pull FScriptContext out of the component and use that.

It sounds to me you want something like (say it’s Lua code): UE.InvokeMethod(Object, “MethodName”, Arg1, Arg2), is that correct? You could do that with UClass/UProperties/UFunctions.

Sounds simple enough.
I am trying to this compiled but I think master is broken, or at least I am having trouble getting everything compiled.
Once I get past this I will get to tinker with it and ill be back with more questions!

UPDATE: Compile problems went away overnight!

UPDATE: Just Kidding.

Tried to use this with 4.1

Discovering modules, targets and source code for game…
UnrealBuildTool Exception: ERROR: Module entry ‘ScriptGeneratorPlugin’ specified an unrecognized module Type ‘Program’ in plugin descriptor file ‘ScriptGeneratorPlugin’

Strange. Looks like you don’t have the latest UBT source files? I did this today and it worked fine.

I was able to get everything fixed so I now have a compiled up to date version of master, but I am having trouble including the proper header files to interface with the plugin from C++ side. I’m assuming there is something you have to edit to specify that you want a plugin dir to end up in the include path for the project.

I know these questions are more about the build system than anything else, I’m just motivated to get this working, because I have a few hundred lines of Lua psuedo-code already written for pieces of my game logic.

EDIT:

This seems to have done the trick!!

This happened when I tried to instantiate a ScriptComponent in my constructor!

Something about the macros isn’t working for this class? Or am I missing something still?

Yeah, you need this:


class **SCRIPTPLUGIN_API** UScriptComponent : public UActorComponent

I’ll make this change on our end too.