Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How To Call ToString () methods from Lua? #48

Closed
napalm44 opened this issue Jun 4, 2015 · 2 comments
Closed

How To Call ToString () methods from Lua? #48

napalm44 opened this issue Jun 4, 2015 · 2 comments

Comments

@napalm44
Copy link

napalm44 commented Jun 4, 2015

HI,
I am trying to do something like this:

Debug.Log ("Object position: " .. self.go.transform.position);

to print the position of my gameobject, however it is trying to concatenate the actual Vector3 to "Object position: ", as opposed to the ToStringed version of the vector3.

Slua also can not seem to find the ToString methods if I try "Debug.Log ("Object position: " ... self.go.transform.position.ToString ()), or position:ToString().

The only way I am able to print the vector normally is Debug.Log (self.go.transform.position). print(self.go.transform.position) just prints the memory/table address as well, which is not desired.

Is there anyway to grab the ToString from a c# script/object member?

EDIT: Larger question: How do I access (or generate code for) the System namespace/functions from LuaJit so that I can use System.* classes?

@pangweiwei
Copy link
Owner

xxx:ToString() or Slua.ToString

@pangweiwei
Copy link
Owner

add type of system.* to OnAddCustomClass, like:

public static void OnAddCustomClass(LuaCodeGen.ExportGenericDelegate add)
{
add(typeof(System.Func), null);
add(typeof(System.Action<int, string>), null);
add(typeof(System.Action<int, Dictionary<int, object>>), null);
add(typeof(List), "ListInt");
add(typeof(Dictionary<int, string>), "DictIntStr");
add(typeof(string), "String");
// add your custom class here
// add( type, typename)
// type is what you want to export
// typename used for simplify generic type name or rename, like List named to "ListInt", if not a generic type keep typename as null or rename as new type name
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants