ZFFramework
Loading...
Searching...
No Matches
Functions
ZFLuaExecute.h File Reference

execute lua script More...

#include "ZFLuaDef.h"

Go to the source code of this file.

Functions

zfauto ZFLuaExecute (const ZFInput &input)
 main entry for lua module, execute lua code
 
zfauto ZFLuaExecute (const zfchar *buf)
 see ZFLuaExecute
 
zfauto ZFLuaExecute (const ZFInput &input, ZFObject *param0, ZFObject *param1=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param2=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param3=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param4=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param5=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param6=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)))
 see ZFLuaExecute
 
zfauto ZFLuaExecute (const zfchar *buf, ZFObject *param0, ZFObject *param1=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param2=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param3=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param4=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param5=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)), ZFObject *param6=(((ZFObject *const &) _ZFP_ZFMethodGenericInvokerDefaultParamRef)))
 see ZFLuaExecute
 
zfauto ZFLuaExecuteDetail (const ZFInput &input, const ZFCoreArray< zfauto > &luaParams, void *L=(0))
 see ZFLuaExecute
 
zfauto ZFLuaExecuteDetail (const zfchar *buf, const ZFCoreArray< zfauto > &luaParams, void *L=(0))
 see ZFLuaExecute
 

Detailed Description

execute lua script

Function Documentation

◆ ZFLuaExecute()

zfauto ZFLuaExecute ( const ZFInput & input)
extern

main entry for lua module, execute lua code

thanks to powerful reflection mechanism in ZFFramework, most of components are registered to lua by reflection automatically

all types of ZFFramework are wrapped as zfauto in lua world, including: ZFObject types (wrapped directly) and non-ZFObject normal C++ types (wrapped by ZFTypeIdWrapper)
then, all reflectable ZFMethod supply ZFMethodGenericInvoker to invoke the method without knowing all actual types

here is a list of functions available in lua to communicate with ZFFramework:

  • "zfAlloc("ClassName" [params...])" or "ClassName([params...])"
    alloc a ZFObject type
    "ClassName" can be v_ZFClass, v_zfstring, or native lua string
    if extra init param passed, your class must supplys reflectable ZFObject::objectOnInit
  • invoker
    • "ret = zfl_call(obj, "functionName", param0, param1, ...)" or "obj:functionName(param0, param1, ...)"
      call object's instance method, params are optional
      for "functionName", see ZFTypeId_ZFMethod
      "functionName" can be v_ZFMethod, v_zfstring, or native lua string, while other types must exactly match the original types
    • "ret = zfl_call(zfnull, "ClassOrNamespace.methodName", param0, param1, ...)" or "ret = ClassOrNamespace.methodName(param0, param1, ...)"
      call global function or static class member method, params are optional
      for "functionName", see ZFTypeId_ZFMethod
      "functionName" can be v_ZFMethod, v_zfstring, v_ZFClass, or native lua string, while other types must exactly match the original types
      these namespace are considered as the same:
    • while calling functions with lua raw string, such as "func('abc')", we will try to convert to proper param type by string converter, if overload functions exists, conversion may take more than once, until it matches first function
  • ZFEnum
    • "YourEnum.e_YourEnumValue()"
      access the enum value
    • "YourEnumFlags('YourEnumValue1|YourEnumValue2')" or "YourEnumFlags(YourEnum.e_YourEnumValue1(), YourEnum.e_YourEnumValue2, ...)"
      create enum flags
  • value holder
    • "value = YourTypeName("yourTypeData")" or "value = zfAlloc("YourTypeName")" or "value = YourTypeName()"
      create a non-ZFObject type registered by ZFTYPEID_DECLARE, return the associated "YourTypeName" that holds the value
      "YourTypeName" represents the type name in ZFTYPEID_DECLARE
      "yourTypeData" store string datas that would be decoded by YourTypeNameFromString
      "yourTypeData" can be v_zfstring, or native lua string
      if your value holder supplys reflectable ZFObject::objectOnInit (ZFOBJECT_ON_INIT_DECLARE_2 series), the value holder can also be constructed by function like call: "YourTypeName(param0, param1)"
    • "value:yourFunc()" or "YourTypeName.YourFunc()"
      for non-ZFObject types that wrapped by ZFTYPEID_DECLARE, you may use ZFMETHOD_USER_REGISTER_0 series to register methods to its wrapper type "YourTypeName", then the methods can be invoked directly to your value type
  • value converter
    • "zfl_value(v)"
      convert a value to lua's raw value, the result lua value can be:
      • lua string
      • lua integer
      • lua number
      • lua boolean
    • these types are automatically converted when return from cpp to lua:
  • callback
    • "ZFCallbackForLua(luaFunc)"
      create a ZFListener from lua function
      the lua function's proto type must be:

      function myLuaCallback(zfargs)
      end


      about thread safe:

      • when the callback called in the same ZFThread where the callback created, the callback should work as expected, all variable capture should work
      • when the callback called in different ZFThread:
        • the callback and all captured upvalues would be copied to a new lua state managed by the ZFThread
        • only these value types can be captured:
          • lua primitive types: boolean, integer, number, string
          • ZFObject types


      further more, lua function can be converted to ZFListener implicitly

      button:observerAdd(ZFUIButton.EventButtonOnClick(), function(zfargs)
      end)
      abstract button
      Definition ZFUIButton.h:41
      static zfidentity EventButtonOnClick(void)
      see ZFObject::observerNotify
      Definition ZFUIButton.h:56
    • "output:output(text[, size, result])"
      write to output callback
    • "input:input(buf [, size, result])"
      read from input callback
  • array
    • "ZFCoreArrayCreate([a, b, c, ...])"
      create a array, params support these types:
  • param and return value
    • simply use lua standard logic to process params and return values, here's some example:
      -- get all params
      local args = {...};
      local argsCount = #args;
      -- return value
      return args[1];
      note that, all params passed from ZFLuaExecute are all zfauto type
  • util
    • "zfstringAppend(s, fmt, ...)" or "zfstr(fmt, ...)"
      fmt can be v_zfstring, or native lua string
      following va_args support:

      note: the va_args support params up to ZFMETHOD_MAX_PARAM

  • local path info spec
    • "zfl_L()"
      lua_State of current chunk, stored as v_ZFPtr
    • "ZFLocalPathInfo()"
      return path info of current context, null if not available
    • "zfimport(localFilePath)"
      util method for ZFLuaExecute + ZFInputForLocal, useful to load local resource or class definition
  • debug helper
    • "zfLog(fmt, ...)" or zfLogTrim(fmt, ...)
      use zfstringAppend then output to zfLog
    • "zfl_tableInfo(v)" or "zfl_tableInfoPrint(v)"
      return string that represents the table

note:

  • all types would be registered automatically,
  • for dynamically loaded library, all types would also be registered normally, however, won't be automatically unregistered when unloaded