Using the Lua target to create a WoW Addon

74 views
Skip to first unread message

Luke Selman

unread,
Sep 19, 2016, 4:20:55 PM9/19/16
to Haxe
I am currently testing out and considering making an extern for the WoW API for Haxe to target Lua, and I'm using a very basic example to test.

I am using this very simple example:

print("Hello " .. UnitName("player"))

and this example in Haxe looks like:

package;

import wowapi.Unit;

class Main
{
static function print(message:String) untyped __lua__("print(message)");

public static function main()
{
var name = Unit.unitName("player");
print("Hello " + name);
}
}

This is the generated (relevant) code for the final lua file:

wowapi.Unit.new = {}
wowapi.Unit.__name__ = true
wowapi.Unit.unitName = function(type) 
  local name, realm = UnitName(type);
  local result = "";
  result = name .. realm;
  do return result end;
end

Main.new = {}
Main.__name__ = true
Main.print = function(message) 
  print(message);
end
Main.main = function() 
  Main.print("Hello " .. wowapi.Unit.unitName("player"));
end

Main.main()


The very simple lua example works in-game, as you would expect. But the Haxe-generated code doesn't. I'm not using extern classes because the Haxe-generated code does not generate it correctly, but I use the untyped __lua__ method like so:

public static function unitName(type:String):String
{
untyped __lua__("local name, realm = UnitName(type)");
var result = "";
untyped __lua__("result = name .. realm");
return result;
}

I simplified the function to only include the name of the character, but that yet still did not print anything.

I don't know if it's World of Warcraft itself or something to do with the generated Haxe code, but it seems a Main.main() function call does not seem to work as a plain single-line, such as the first code example, does.

I tried doing a simple lua example using a function instead to see if a plain example would work, which it doesn't meaning that WoW itself doesn't allow for function calls like that. That simple function declaration example I am using is:

myFunction = function() {
  print("Hello " .. UnitName("player"));
}

myFunction()

Which would mean that Haxe-generated code won't work for World of Warcraft addons, which is disappointing. Any ideas?

Luke Selman

unread,
Sep 19, 2016, 4:27:53 PM9/19/16
to Haxe
myFunction = function()
 print("Hello " .. UnitName("player"));
end

myFunction()

I changed the last code to the above, because I didn't understand lua functions (clearly) and this is now what it looks like. I tested this in-game, and this basic example works.

Justin Donaldson

unread,
Sep 19, 2016, 5:01:18 PM9/19/16
to Haxe
Hi Luke, 

Great to see someone working on this!

I have an early demo I worked on here:  

Note that Wow does not provide a "normal" lua environment.  It's necessary to work around some missing methods, etc.  You can see where I did that in the repo.

The reality for now is that the lua target is still in alpha stage.  You can get things working with some effort, but there's some rough edges. However, there's been some nice improvements necessary for proper wow scripting support : lua 5.1 support, and multireturn support.  You'll find these features in the development branch.  However, they're still undocumented.

You can simplify your UnitName extern definition with:

@:native("_G")
extern class Wow {
  public static function UnitName(arg:String) : UnitNameResult;
}

@:multiReturn
extern class UnitNameResult {
  var name : String;
  var realm : String;
}

You can then use the method as follows:

var res = Wow.UnitName("player");
print(res.name);
print(res.realm);

It's a lot easier to deal with than using untyped code.

Keep on the lookout for more lua extern features.  This is under active development right now.

Best,
-Justin



--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Luke Selman

unread,
Sep 19, 2016, 6:05:23 PM9/19/16
to Haxe
I tried your code examples with no effect, and also tried HaxeCraft and used some of the examples there, such as changing the extern around:

package wowapi;

@:native("_G")
extern class Wow {
public static function UnitName(target:Dynamic) : String;
//Utils
public static function print(message:Dynamic):Void;
}

But, again, with no effect. HaxeCraft is 4 months old, and since then Legion has been released so the likelihood that the WoW API has changed is quite high and certain Haxe-generated code might cause some issues. 

Also, in the new patch, there is no way from the options menu to turn on Lua errors so I have no clue how to debug which is really frustrating. I will get back tomorrow once I've had some sleep and have figured out how to turn on Lua errors :)
Reply all
Reply to author
Forward
0 new messages