LuaScript.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "CoreEvents.h"
  24. #include "EngineEvents.h"
  25. #include "File.h"
  26. #include "Log.h"
  27. #include "LuaFile.h"
  28. #include "LuaFunction.h"
  29. #include "LuaScript.h"
  30. #include "LuaScriptInstance.h"
  31. #include "ProcessUtils.h"
  32. #include "Profiler.h"
  33. #include "ResourceCache.h"
  34. #include "Scene.h"
  35. extern "C"
  36. {
  37. #include <lua.h>
  38. #include <lualib.h>
  39. #include <lauxlib.h>
  40. }
  41. #include "tolua++.h"
  42. #include "ToluaUtils.h"
  43. #include "DebugNew.h"
  44. extern int tolua_AudioLuaAPI_open(lua_State*);
  45. extern int tolua_CoreLuaAPI_open(lua_State*);
  46. extern int tolua_EngineLuaAPI_open(lua_State*);
  47. extern int tolua_GraphicsLuaAPI_open(lua_State*);
  48. extern int tolua_InputLuaAPI_open(lua_State*);
  49. extern int tolua_IOLuaAPI_open(lua_State*);
  50. extern int tolua_MathLuaAPI_open(lua_State*);
  51. #ifdef URHO3D_NAVIGATION
  52. extern int tolua_NavigationLuaAPI_open(lua_State*);
  53. #endif
  54. #ifdef URHO3D_NETWORK
  55. extern int tolua_NetworkLuaAPI_open(lua_State*);
  56. #endif
  57. #ifdef URHO3D_PHYSICS
  58. extern int tolua_PhysicsLuaAPI_open(lua_State*);
  59. #endif
  60. extern int tolua_ResourceLuaAPI_open(lua_State*);
  61. extern int tolua_SceneLuaAPI_open(lua_State*);
  62. extern int tolua_UILuaAPI_open(lua_State*);
  63. #ifdef URHO3D_URHO2D
  64. extern int tolua_Urho2DLuaAPI_open(lua_State*);
  65. #endif
  66. extern int tolua_LuaScriptLuaAPI_open(lua_State*);
  67. namespace Urho3D
  68. {
  69. LuaScript::LuaScript(Context* context) :
  70. Object(context),
  71. luaState_(0),
  72. executeConsoleCommands_(false)
  73. {
  74. RegisterLuaScriptLibrary(context_);
  75. luaState_ = luaL_newstate();
  76. if (!luaState_)
  77. {
  78. LOGERROR("Could not create Lua state");
  79. return;
  80. }
  81. SetContext(luaState_, context_);
  82. lua_atpanic(luaState_, &LuaScript::AtPanic);
  83. luaL_openlibs(luaState_);
  84. RegisterLoader();
  85. ReplacePrint();
  86. tolua_MathLuaAPI_open(luaState_);
  87. tolua_CoreLuaAPI_open(luaState_);
  88. tolua_IOLuaAPI_open(luaState_);
  89. tolua_ResourceLuaAPI_open(luaState_);
  90. tolua_SceneLuaAPI_open(luaState_);
  91. tolua_AudioLuaAPI_open(luaState_);
  92. tolua_EngineLuaAPI_open(luaState_);
  93. tolua_GraphicsLuaAPI_open(luaState_);
  94. tolua_InputLuaAPI_open(luaState_);
  95. #ifdef URHO3D_NAVIGATION
  96. tolua_NavigationLuaAPI_open(luaState_);
  97. #endif
  98. #ifdef URHO3D_NETWORK
  99. tolua_NetworkLuaAPI_open(luaState_);
  100. #endif
  101. #ifdef URHO3D_PHYSICS
  102. tolua_PhysicsLuaAPI_open(luaState_);
  103. #endif
  104. tolua_UILuaAPI_open(luaState_);
  105. #ifdef URHO3D_URHO2D
  106. tolua_Urho2DLuaAPI_open(luaState_);
  107. #endif
  108. tolua_LuaScriptLuaAPI_open(luaState_);
  109. coroutineUpdate_ = GetFunction("coroutine.update");
  110. // Subscribe to post update
  111. SubscribeToEvent(E_POSTUPDATE, HANDLER(LuaScript, HandlePostUpdate));
  112. // Subscribe to console commands
  113. SetExecuteConsoleCommands(true);
  114. // Record the internally handled script functions so that UnsubscribeFromAllEvents doesn't destroy them
  115. internalEvents_.Push(E_POSTUPDATE);
  116. internalEvents_.Push(E_CONSOLECOMMAND);
  117. }
  118. LuaScript::~LuaScript()
  119. {
  120. functionNameToFunctionMap_.Clear();
  121. lua_State* luaState = luaState_;
  122. luaState_ = 0;
  123. SetContext(luaState_, 0);
  124. if (luaState)
  125. lua_close(luaState);
  126. }
  127. bool LuaScript::ExecuteFile(const String& fileName)
  128. {
  129. PROFILE(ExecuteFile);
  130. ResourceCache* cache = GetSubsystem<ResourceCache>();
  131. LuaFile* luaFile = cache->GetResource<LuaFile>(fileName);
  132. return luaFile && luaFile->LoadAndExecute(luaState_);
  133. }
  134. bool LuaScript::ExecuteString(const String& string)
  135. {
  136. PROFILE(ExecuteString);
  137. int top = lua_gettop(luaState_);
  138. if (luaL_dostring(luaState_, string.CString()) != 0)
  139. {
  140. const char* message = lua_tostring(luaState_, -1);
  141. LOGERROR("Execute Lua string failed: " + String(message));
  142. lua_settop(luaState_, top);
  143. return false;
  144. }
  145. return true;
  146. }
  147. bool LuaScript::ExecuteFunction(const String& functionName)
  148. {
  149. WeakPtr<LuaFunction> function = GetFunction(functionName);
  150. return function && function->BeginCall() && function->EndCall();
  151. }
  152. void LuaScript::ScriptSendEvent(const String& eventName, VariantMap& eventData)
  153. {
  154. SendEvent(StringHash(eventName), eventData);
  155. }
  156. void LuaScript::ScriptSubscribeToEvent(const String& eventName, int functionIndex)
  157. {
  158. StringHash eventType(eventName);
  159. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  160. if (function)
  161. {
  162. LuaFunctionVector& functions = eventHandleFunctions_[eventType];
  163. SubscribeToEvent(eventType, HANDLER(LuaScript, HandleEvent));
  164. if (!functions.Contains(function))
  165. functions.Push(function);
  166. }
  167. }
  168. void LuaScript::ScriptSubscribeToEvent(const String& eventName, const String& functionName)
  169. {
  170. StringHash eventType(eventName);
  171. WeakPtr<LuaFunction> function = GetFunction(functionName);
  172. if (function)
  173. {
  174. LuaFunctionVector& functions = eventHandleFunctions_[eventType];
  175. SubscribeToEvent(eventType, HANDLER(LuaScript, HandleEvent));
  176. if (!functions.Contains(function))
  177. functions.Push(function);
  178. }
  179. }
  180. void LuaScript::ScriptUnsubscribeFromEvent(const String& eventName)
  181. {
  182. StringHash eventType(eventName);
  183. HashMap<StringHash, LuaFunctionVector>::Iterator i = eventHandleFunctions_.Find(eventType);
  184. if (i != eventHandleFunctions_.End())
  185. {
  186. LuaFunctionVector& functions = i->second_;
  187. UnsubscribeFromEvent(eventType);
  188. eventHandleFunctions_.Erase(i);
  189. }
  190. }
  191. void LuaScript::ScriptUnsubscribeFromEvent(const String& eventName, int functionIndex)
  192. {
  193. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  194. if (!function)
  195. return;
  196. StringHash eventType(eventName);
  197. HashMap<StringHash, LuaFunctionVector>::Iterator i = eventHandleFunctions_.Find(eventType);
  198. if (i != eventHandleFunctions_.End())
  199. {
  200. LuaFunctionVector& functions = i->second_;
  201. functions.Remove(function);
  202. if (functions.Empty())
  203. {
  204. UnsubscribeFromEvent(eventType);
  205. eventHandleFunctions_.Erase(i);
  206. }
  207. }
  208. }
  209. void LuaScript::ScriptUnsubscribeFromEvent(const String& eventName, const String& functionName)
  210. {
  211. if (functionName.Empty())
  212. return;
  213. WeakPtr<LuaFunction> function = GetFunction(functionName);
  214. if (!function)
  215. return;
  216. StringHash eventType(eventName);
  217. HashMap<StringHash, LuaFunctionVector>::Iterator i = eventHandleFunctions_.Find(eventType);
  218. if (i != eventHandleFunctions_.End())
  219. {
  220. LuaFunctionVector& functions = i->second_;
  221. functions.Remove(function);
  222. if (functions.Empty())
  223. {
  224. UnsubscribeFromEvent(eventType);
  225. eventHandleFunctions_.Erase(i);
  226. }
  227. }
  228. }
  229. void LuaScript::ScriptUnsubscribeFromAllEvents()
  230. {
  231. if (eventHandleFunctions_.Empty())
  232. return;
  233. UnsubscribeFromAllEventsExcept(internalEvents_, false);
  234. eventHandleFunctions_.Clear();
  235. }
  236. void LuaScript::ScriptSubscribeToEvent(void* sender, const String& eventName, int functionIndex)
  237. {
  238. StringHash eventType(eventName);
  239. Object* object = (Object*)sender;
  240. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  241. if (function)
  242. {
  243. LuaFunctionVector& functions = objectHandleFunctions_[object][eventType];
  244. // Fix issue #256
  245. HashSet<Object*>* receivers = context_->GetEventReceivers(object, eventType);
  246. if ((!receivers || !receivers->Contains(this)) && !functions.Empty())
  247. functions.Clear();
  248. SubscribeToEvent(object, eventType, HANDLER(LuaScript, HandleObjectEvent));
  249. if (!functions.Contains(function))
  250. functions.Push(function);
  251. }
  252. }
  253. void LuaScript::ScriptSubscribeToEvent(void* sender, const String& eventName, const String& functionName)
  254. {
  255. StringHash eventType(eventName);
  256. Object* object = (Object*)sender;
  257. WeakPtr<LuaFunction> function = GetFunction(functionName);
  258. if (function)
  259. {
  260. LuaFunctionVector& functions = objectHandleFunctions_[object][eventType];
  261. // Fix issue #256
  262. HashSet<Object*>* receivers = context_->GetEventReceivers(object, eventType);
  263. if ((!receivers || !receivers->Contains(this)) && !functions.Empty())
  264. functions.Clear();
  265. SubscribeToEvent(object, eventType, HANDLER(LuaScript, HandleObjectEvent));
  266. if (!functions.Contains(function))
  267. functions.Push(function);
  268. }
  269. }
  270. void LuaScript::ScriptUnsubscribeFromEvent(void* sender, const String& eventName)
  271. {
  272. StringHash eventType(eventName);
  273. Object* object = (Object*)sender;
  274. HashMap<StringHash, LuaFunctionVector>::Iterator i = objectHandleFunctions_[object].Find(eventType);
  275. if (i != objectHandleFunctions_[object].End())
  276. {
  277. LuaFunctionVector& functions = i->second_;
  278. UnsubscribeFromEvent(object, eventType);
  279. objectHandleFunctions_[object].Erase(i);
  280. }
  281. }
  282. void LuaScript::ScriptUnsubscribeFromEvent(void* sender, const String& eventName, int functionIndex)
  283. {
  284. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  285. if (!function)
  286. return;
  287. StringHash eventType(eventName);
  288. Object* object = (Object*)sender;
  289. HashMap<StringHash, LuaFunctionVector>::Iterator i = objectHandleFunctions_[object].Find(eventType);
  290. if (i != objectHandleFunctions_[object].End())
  291. {
  292. LuaFunctionVector& functions = i->second_;
  293. functions.Remove(function);
  294. if (functions.Empty())
  295. {
  296. UnsubscribeFromEvent(object, eventType);
  297. objectHandleFunctions_[object].Erase(i);
  298. }
  299. }
  300. }
  301. void LuaScript::ScriptUnsubscribeFromEvent(void* sender, const String& eventName, const String& functionName)
  302. {
  303. WeakPtr<LuaFunction> function = GetFunction(functionName);
  304. if (!function)
  305. return;
  306. StringHash eventType(eventName);
  307. Object* object = (Object*)sender;
  308. HashMap<StringHash, LuaFunctionVector>::Iterator i = objectHandleFunctions_[object].Find(eventType);
  309. if (i != objectHandleFunctions_[object].End())
  310. {
  311. LuaFunctionVector& functions = i->second_;
  312. functions.Remove(function);
  313. if (functions.Empty())
  314. {
  315. UnsubscribeFromEvent(object, eventType);
  316. objectHandleFunctions_[object].Erase(i);
  317. }
  318. }
  319. }
  320. void LuaScript::ScriptUnsubscribeFromEvents(void* sender)
  321. {
  322. Object* object = (Object*)sender;
  323. HashMap<Object*, HashMap<StringHash, LuaFunctionVector> >::Iterator it = objectHandleFunctions_.Find(object);
  324. if (it == objectHandleFunctions_.End())
  325. return;
  326. UnsubscribeFromEvents(object);
  327. objectHandleFunctions_.Erase(it);
  328. }
  329. void LuaScript::SetExecuteConsoleCommands(bool enable)
  330. {
  331. if (enable == executeConsoleCommands_)
  332. return;
  333. executeConsoleCommands_ = enable;
  334. if (enable)
  335. SubscribeToEvent(E_CONSOLECOMMAND, HANDLER(LuaScript, HandleConsoleCommand));
  336. else
  337. UnsubscribeFromEvent(E_CONSOLECOMMAND);
  338. }
  339. void LuaScript::RegisterLoader()
  340. {
  341. // Get package.loaders table
  342. lua_getglobal(luaState_, "package");
  343. lua_getfield(luaState_, -1, "loaders");
  344. // Add LuaScript::Loader to the end of the table
  345. lua_pushinteger(luaState_, lua_objlen(luaState_, -1) + 1);
  346. lua_pushcfunction(luaState_, &LuaScript::Loader);
  347. lua_settable(luaState_, -3);
  348. lua_pop(luaState_, 2);
  349. }
  350. int LuaScript::AtPanic(lua_State* L)
  351. {
  352. String errorMessage = luaL_checkstring(L, -1);
  353. LOGERROR("Lua error: Error message = '" + errorMessage + "'");
  354. lua_pop(L, 1);
  355. return 0;
  356. }
  357. int LuaScript::Loader(lua_State* L)
  358. {
  359. ResourceCache* cache = ::GetContext(L)->GetSubsystem<ResourceCache>();
  360. // Get module name
  361. const char* name = luaL_checkstring(L, 1);
  362. // Attempt to get .luc file first.
  363. String lucFileName = String(name) + ".luc";
  364. LuaFile* lucFile = cache->GetResource<LuaFile>(lucFileName, false);
  365. if (lucFile)
  366. return lucFile->LoadChunk(L) ? 1 : 0;
  367. // Then try to get .lua file. If this also fails, error is logged and resource not found event is sent
  368. String luaFileName = String(name) + ".lua";
  369. LuaFile* luaFile = cache->GetResource<LuaFile>(luaFileName);
  370. if (luaFile)
  371. return luaFile->LoadChunk(L) ? 1 : 0;
  372. return 0;
  373. }
  374. void LuaScript::ReplacePrint()
  375. {
  376. static const struct luaL_reg reg[] =
  377. {
  378. {"print", &LuaScript::Print},
  379. { NULL, NULL}
  380. };
  381. lua_getglobal(luaState_, "_G");
  382. luaL_register(luaState_, NULL, reg);
  383. lua_pop(luaState_, 1);
  384. }
  385. int LuaScript::Print(lua_State *L)
  386. {
  387. String string;
  388. int n = lua_gettop(L);
  389. lua_getglobal(L, "tostring");
  390. for (int i = 1; i <= n; i++)
  391. {
  392. const char *s;
  393. // Function to be called
  394. lua_pushvalue(L, -1);
  395. // Value to print
  396. lua_pushvalue(L, i);
  397. lua_call(L, 1, 1);
  398. // Get result
  399. s = lua_tostring(L, -1);
  400. if (s == NULL)
  401. return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
  402. if (i > 1)
  403. string.Append(" ");
  404. string.Append(s);
  405. // Pop result
  406. lua_pop(L, 1);
  407. }
  408. LOGRAW(string + "\n");
  409. return 0;
  410. }
  411. WeakPtr<LuaFunction> LuaScript::GetFunction(int functionIndex)
  412. {
  413. if (!lua_isfunction(luaState_, functionIndex))
  414. return WeakPtr<LuaFunction>();
  415. const void* functionPointer = lua_topointer(luaState_, functionIndex);
  416. if (!functionPointer)
  417. return WeakPtr<LuaFunction>();
  418. HashMap<const void*, SharedPtr<LuaFunction> >::Iterator i = functionPointerToFunctionMap_.Find(functionPointer);
  419. if (i != functionPointerToFunctionMap_.End())
  420. return WeakPtr<LuaFunction>(i->second_);
  421. lua_pushvalue(luaState_, functionIndex);
  422. int functionRef = luaL_ref(luaState_, LUA_REGISTRYINDEX);
  423. SharedPtr<LuaFunction> function(new LuaFunction(luaState_, functionRef, false));
  424. functionPointerToFunctionMap_[functionPointer] = function;
  425. return WeakPtr<LuaFunction>(function);
  426. }
  427. WeakPtr<LuaFunction> LuaScript::GetFunction(const String& functionName, bool silentIfNotFound)
  428. {
  429. if (!luaState_)
  430. return WeakPtr<LuaFunction>();
  431. HashMap<String, SharedPtr<LuaFunction> >::Iterator i = functionNameToFunctionMap_.Find(functionName);
  432. if (i != functionNameToFunctionMap_.End())
  433. return WeakPtr<LuaFunction>(i->second_);
  434. int top = lua_gettop(luaState_);
  435. SharedPtr<LuaFunction> function;
  436. if (PushScriptFunction(functionName, silentIfNotFound))
  437. {
  438. int ref = luaL_ref(luaState_, LUA_REGISTRYINDEX);
  439. function = new LuaFunction(luaState_, ref);
  440. }
  441. lua_settop(luaState_, top);
  442. functionNameToFunctionMap_[functionName] = function;
  443. return WeakPtr<LuaFunction>(function);
  444. }
  445. void LuaScript::HandleEvent(StringHash eventType, VariantMap& eventData)
  446. {
  447. LuaFunctionVector& functions = eventHandleFunctions_[eventType];
  448. for (unsigned i = 0; i < functions.Size(); ++i)
  449. {
  450. WeakPtr<LuaFunction> function = functions[i];
  451. if (function && function->BeginCall())
  452. {
  453. function->PushUserType(eventType, "StringHash");
  454. function->PushUserType(eventData, "VariantMap");
  455. function->EndCall();
  456. }
  457. }
  458. }
  459. void LuaScript::HandleObjectEvent(StringHash eventType, VariantMap& eventData)
  460. {
  461. Object* object = GetEventSender();
  462. LuaFunctionVector& functions = objectHandleFunctions_[object][eventType];
  463. for (unsigned i = 0; i < functions.Size(); ++i)
  464. {
  465. WeakPtr<LuaFunction> function = functions[i];
  466. if (function && function->BeginCall())
  467. {
  468. function->PushUserType(eventType, "StringHash");
  469. function->PushUserType(eventData, "VariantMap");
  470. function->EndCall();
  471. }
  472. }
  473. }
  474. void LuaScript::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
  475. {
  476. // Call also user-subscribed PostUpdate handler (if any)
  477. HandleEvent(eventType, eventData);
  478. if (coroutineUpdate_ && coroutineUpdate_->BeginCall())
  479. {
  480. using namespace PostUpdate;
  481. float timeStep = eventData[P_TIMESTEP].GetFloat();
  482. coroutineUpdate_->PushFloat(timeStep);
  483. coroutineUpdate_->EndCall();
  484. }
  485. // Collect garbage
  486. lua_gc(luaState_, LUA_GCCOLLECT, 0);
  487. }
  488. void LuaScript::HandleConsoleCommand(StringHash eventType, VariantMap& eventData)
  489. {
  490. using namespace ConsoleCommand;
  491. if (eventData[P_ID].GetString() == GetTypeName())
  492. ExecuteString(eventData[P_COMMAND].GetString());
  493. }
  494. bool LuaScript::PushScriptFunction(const String& functionName, bool silentIfNotFound)
  495. {
  496. Vector<String> splitedNames = functionName.Split('.');
  497. String currentName = splitedNames.Front();
  498. lua_getglobal(luaState_, currentName.CString());
  499. if (splitedNames.Size() > 1)
  500. {
  501. if (!lua_istable(luaState_, -1))
  502. {
  503. LOGERROR("Could not find Lua table: Table name = '" + currentName + "'");
  504. return false;
  505. }
  506. for (unsigned i = 1; i < splitedNames.Size() - 1; ++i)
  507. {
  508. currentName = currentName + "." + splitedNames[i];
  509. lua_getfield(luaState_, -1, splitedNames[i].CString());
  510. if (!lua_istable(luaState_, -1))
  511. {
  512. LOGERROR("Could not find Lua table: Table name = '" + currentName + "'");
  513. return false;
  514. }
  515. }
  516. currentName = currentName + "." + splitedNames.Back().CString();
  517. lua_getfield(luaState_, -1, splitedNames.Back().CString());
  518. }
  519. if (!lua_isfunction(luaState_, -1))
  520. {
  521. if (!silentIfNotFound)
  522. LOGERROR("Could not find Lua function: Function name = '" + currentName + "'");
  523. return false;
  524. }
  525. return true;
  526. }
  527. void RegisterLuaScriptLibrary(Context* context)
  528. {
  529. LuaFile::RegisterObject(context);
  530. LuaScriptInstance::RegisterObject(context);
  531. }
  532. }