LuaScript Xojo and Real Studio Plugin |
|
LuaScriptContext.WireInstanceToClass Method (console safe)
Wires a table instance that represents the data of a class to a Lua class declaration.
WireInstanceToClass(
className as String)
Parameters
- className
- The name of the class to wire the data to
Remarks
The data table is expected to be at top of the stack at time of calling this method.
Function NewVector(lua as Ptr) As Integer
Dim context as LuaScriptContext
Dim result as Double
Dim x as Double
Dim y as Double
Dim z as Double
context = new LuaScriptContext(lua)
// Lua does not know how many parameters your function has so it will push all its got to the stack,
// your responsible for making sure your get the correct amount of them
// Note we check for 4 here because of the invisible self parameter
if context.ParameterCount <> 4 then
context.SetError("CustomVector constructor expects 3 parameters") // To the user then it was 3 parameters
return 0
end if
// We fetch the parameters before we construct the result as the stack will change once we start creating new table
x = context.GetDouble(2,false)
y = context.GetDouble(3,false)
z =context.GetDouble(4,false)
// Make a table that stores x,y,z as named values
context.NewTable()
context.Push("x")
context.Push(x)
context.SetTableValue()
context.Push("y")
context.Push(y)
context.SetTableValue()
context.Push("z")
context.Push(z)
context.SetTableValue()
// We wire the class data table as instance to the class method table, if we dont then
// the class will not work. We can call this here since the data table is at this point at top in the stack.
context.WireInstanceToClass("CustomVector")
// We always return 1 here to tell Lua that all was good
return 1
End Function
See Also
LuaScriptContext Class