LuaScript.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. //
  2. // Copyright (c) 2008-2015 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 "../Core/CoreEvents.h"
  23. #include "../Engine/EngineEvents.h"
  24. #include "../IO/File.h"
  25. #include "../IO/Log.h"
  26. #include "../LuaScript/LuaFile.h"
  27. #include "../LuaScript/LuaFunction.h"
  28. #include "../LuaScript/LuaScript.h"
  29. #include "../LuaScript/LuaScriptInstance.h"
  30. #include "../Core/ProcessUtils.h"
  31. #include "../Core/Profiler.h"
  32. #include "../Resource/ResourceCache.h"
  33. #include "../Scene/Scene.h"
  34. extern "C"
  35. {
  36. #include <lualib.h>
  37. }
  38. #include <toluapp/tolua++.h>
  39. #include "../LuaScript/ToluaUtils.h"
  40. #include "../DebugNew.h"
  41. extern int tolua_AudioLuaAPI_open(lua_State*);
  42. extern int tolua_CoreLuaAPI_open(lua_State*);
  43. extern int tolua_EngineLuaAPI_open(lua_State*);
  44. extern int tolua_GraphicsLuaAPI_open(lua_State*);
  45. extern int tolua_InputLuaAPI_open(lua_State*);
  46. extern int tolua_IOLuaAPI_open(lua_State*);
  47. extern int tolua_MathLuaAPI_open(lua_State*);
  48. #ifdef URHO3D_NAVIGATION
  49. extern int tolua_NavigationLuaAPI_open(lua_State*);
  50. #endif
  51. #ifdef URHO3D_NETWORK
  52. extern int tolua_NetworkLuaAPI_open(lua_State*);
  53. #endif
  54. #ifdef URHO3D_PHYSICS
  55. extern int tolua_PhysicsLuaAPI_open(lua_State*);
  56. #endif
  57. extern int tolua_ResourceLuaAPI_open(lua_State*);
  58. extern int tolua_SceneLuaAPI_open(lua_State*);
  59. extern int tolua_UILuaAPI_open(lua_State*);
  60. #ifdef URHO3D_URHO2D
  61. extern int tolua_Urho2DLuaAPI_open(lua_State*);
  62. #endif
  63. extern int tolua_LuaScriptLuaAPI_open(lua_State*);
  64. namespace Urho3D
  65. {
  66. LuaScript::LuaScript(Context* context) :
  67. Object(context),
  68. luaState_(0),
  69. executeConsoleCommands_(false)
  70. {
  71. RegisterLuaScriptLibrary(context_);
  72. luaState_ = luaL_newstate();
  73. if (!luaState_)
  74. {
  75. LOGERROR("Could not create Lua state");
  76. return;
  77. }
  78. SetContext(luaState_, context_);
  79. lua_atpanic(luaState_, &LuaScript::AtPanic);
  80. luaL_openlibs(luaState_);
  81. RegisterLoader();
  82. ReplacePrint();
  83. tolua_MathLuaAPI_open(luaState_);
  84. tolua_CoreLuaAPI_open(luaState_);
  85. tolua_IOLuaAPI_open(luaState_);
  86. tolua_ResourceLuaAPI_open(luaState_);
  87. tolua_SceneLuaAPI_open(luaState_);
  88. tolua_AudioLuaAPI_open(luaState_);
  89. tolua_EngineLuaAPI_open(luaState_);
  90. tolua_GraphicsLuaAPI_open(luaState_);
  91. tolua_InputLuaAPI_open(luaState_);
  92. #ifdef URHO3D_NAVIGATION
  93. tolua_NavigationLuaAPI_open(luaState_);
  94. #endif
  95. #ifdef URHO3D_NETWORK
  96. tolua_NetworkLuaAPI_open(luaState_);
  97. #endif
  98. #ifdef URHO3D_PHYSICS
  99. tolua_PhysicsLuaAPI_open(luaState_);
  100. #endif
  101. tolua_UILuaAPI_open(luaState_);
  102. #ifdef URHO3D_URHO2D
  103. tolua_Urho2DLuaAPI_open(luaState_);
  104. #endif
  105. tolua_LuaScriptLuaAPI_open(luaState_);
  106. coroutineUpdate_ = GetFunction("coroutine.update");
  107. // Subscribe to post update
  108. SubscribeToEvent(E_POSTUPDATE, HANDLER(LuaScript, HandlePostUpdate));
  109. // Subscribe to console commands
  110. SetExecuteConsoleCommands(true);
  111. // Record the internally handled script functions so that UnsubscribeFromAllEvents doesn't destroy them
  112. internalEvents_.Push(E_POSTUPDATE);
  113. internalEvents_.Push(E_CONSOLECOMMAND);
  114. }
  115. LuaScript::~LuaScript()
  116. {
  117. functionNameToFunctionMap_.Clear();
  118. lua_State* luaState = luaState_;
  119. luaState_ = 0;
  120. SetContext(luaState_, 0);
  121. if (luaState)
  122. lua_close(luaState);
  123. }
  124. bool LuaScript::ExecuteFile(const String& fileName)
  125. {
  126. PROFILE(ExecuteFile);
  127. ResourceCache* cache = GetSubsystem<ResourceCache>();
  128. LuaFile* luaFile = cache->GetResource<LuaFile>(fileName);
  129. return luaFile && luaFile->LoadAndExecute(luaState_);
  130. }
  131. bool LuaScript::ExecuteString(const String& string)
  132. {
  133. PROFILE(ExecuteString);
  134. int top = lua_gettop(luaState_);
  135. if (luaL_dostring(luaState_, string.CString()) != 0)
  136. {
  137. const char* message = lua_tostring(luaState_, -1);
  138. LOGERROR("Execute Lua string failed: " + String(message));
  139. lua_settop(luaState_, top);
  140. return false;
  141. }
  142. return true;
  143. }
  144. bool LuaScript::ExecuteFunction(const String& functionName)
  145. {
  146. WeakPtr<LuaFunction> function = GetFunction(functionName);
  147. return function && function->BeginCall() && function->EndCall();
  148. }
  149. void LuaScript::ScriptSendEvent(const String& eventName, VariantMap& eventData)
  150. {
  151. SendEvent(StringHash(eventName), eventData);
  152. }
  153. void LuaScript::ScriptSubscribeToEvent(const String& eventName, int functionIndex)
  154. {
  155. StringHash eventType(eventName);
  156. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  157. if (function)
  158. {
  159. LuaFunctionVector& functions = eventHandleFunctions_[eventType];
  160. SubscribeToEvent(eventType, HANDLER(LuaScript, HandleEvent));
  161. if (!functions.Contains(function))
  162. functions.Push(function);
  163. }
  164. }
  165. void LuaScript::ScriptSubscribeToEvent(const String& eventName, const String& functionName)
  166. {
  167. StringHash eventType(eventName);
  168. WeakPtr<LuaFunction> function = GetFunction(functionName);
  169. if (function)
  170. {
  171. LuaFunctionVector& functions = eventHandleFunctions_[eventType];
  172. SubscribeToEvent(eventType, HANDLER(LuaScript, HandleEvent));
  173. if (!functions.Contains(function))
  174. functions.Push(function);
  175. }
  176. }
  177. void LuaScript::ScriptUnsubscribeFromEvent(const String& eventName)
  178. {
  179. StringHash eventType(eventName);
  180. HashMap<StringHash, LuaFunctionVector>::Iterator i = eventHandleFunctions_.Find(eventType);
  181. if (i != eventHandleFunctions_.End())
  182. {
  183. LuaFunctionVector& functions = i->second_;
  184. UnsubscribeFromEvent(eventType);
  185. eventHandleFunctions_.Erase(i);
  186. }
  187. }
  188. void LuaScript::ScriptUnsubscribeFromEvent(const String& eventName, int functionIndex)
  189. {
  190. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  191. if (!function)
  192. return;
  193. StringHash eventType(eventName);
  194. HashMap<StringHash, LuaFunctionVector>::Iterator i = eventHandleFunctions_.Find(eventType);
  195. if (i != eventHandleFunctions_.End())
  196. {
  197. LuaFunctionVector& functions = i->second_;
  198. functions.Remove(function);
  199. if (functions.Empty())
  200. {
  201. UnsubscribeFromEvent(eventType);
  202. eventHandleFunctions_.Erase(i);
  203. }
  204. }
  205. }
  206. void LuaScript::ScriptUnsubscribeFromEvent(const String& eventName, const String& functionName)
  207. {
  208. if (functionName.Empty())
  209. return;
  210. WeakPtr<LuaFunction> function = GetFunction(functionName);
  211. if (!function)
  212. return;
  213. StringHash eventType(eventName);
  214. HashMap<StringHash, LuaFunctionVector>::Iterator i = eventHandleFunctions_.Find(eventType);
  215. if (i != eventHandleFunctions_.End())
  216. {
  217. LuaFunctionVector& functions = i->second_;
  218. functions.Remove(function);
  219. if (functions.Empty())
  220. {
  221. UnsubscribeFromEvent(eventType);
  222. eventHandleFunctions_.Erase(i);
  223. }
  224. }
  225. }
  226. void LuaScript::ScriptUnsubscribeFromAllEvents()
  227. {
  228. if (eventHandleFunctions_.Empty())
  229. return;
  230. UnsubscribeFromAllEventsExcept(internalEvents_, false);
  231. eventHandleFunctions_.Clear();
  232. }
  233. void LuaScript::ScriptSubscribeToEvent(void* sender, const String& eventName, int functionIndex)
  234. {
  235. StringHash eventType(eventName);
  236. Object* object = (Object*)sender;
  237. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  238. if (function)
  239. {
  240. LuaFunctionVector& functions = objectHandleFunctions_[object][eventType];
  241. // Fix issue #256
  242. HashSet<Object*>* receivers = context_->GetEventReceivers(object, eventType);
  243. if ((!receivers || !receivers->Contains(this)) && !functions.Empty())
  244. functions.Clear();
  245. SubscribeToEvent(object, eventType, HANDLER(LuaScript, HandleObjectEvent));
  246. if (!functions.Contains(function))
  247. functions.Push(function);
  248. }
  249. }
  250. void LuaScript::ScriptSubscribeToEvent(void* sender, const String& eventName, const String& functionName)
  251. {
  252. StringHash eventType(eventName);
  253. Object* object = (Object*)sender;
  254. WeakPtr<LuaFunction> function = GetFunction(functionName);
  255. if (function)
  256. {
  257. LuaFunctionVector& functions = objectHandleFunctions_[object][eventType];
  258. // Fix issue #256
  259. HashSet<Object*>* receivers = context_->GetEventReceivers(object, eventType);
  260. if ((!receivers || !receivers->Contains(this)) && !functions.Empty())
  261. functions.Clear();
  262. SubscribeToEvent(object, eventType, HANDLER(LuaScript, HandleObjectEvent));
  263. if (!functions.Contains(function))
  264. functions.Push(function);
  265. }
  266. }
  267. void LuaScript::ScriptUnsubscribeFromEvent(void* sender, const String& eventName)
  268. {
  269. StringHash eventType(eventName);
  270. Object* object = (Object*)sender;
  271. HashMap<StringHash, LuaFunctionVector>::Iterator i = objectHandleFunctions_[object].Find(eventType);
  272. if (i != objectHandleFunctions_[object].End())
  273. {
  274. LuaFunctionVector& functions = i->second_;
  275. UnsubscribeFromEvent(object, eventType);
  276. objectHandleFunctions_[object].Erase(i);
  277. }
  278. }
  279. void LuaScript::ScriptUnsubscribeFromEvent(void* sender, const String& eventName, int functionIndex)
  280. {
  281. WeakPtr<LuaFunction> function = GetFunction(functionIndex);
  282. if (!function)
  283. return;
  284. StringHash eventType(eventName);
  285. Object* object = (Object*)sender;
  286. HashMap<StringHash, LuaFunctionVector>::Iterator i = objectHandleFunctions_[object].Find(eventType);
  287. if (i != objectHandleFunctions_[object].End())
  288. {
  289. LuaFunctionVector& functions = i->second_;
  290. functions.Remove(function);
  291. if (functions.Empty())
  292. {
  293. UnsubscribeFromEvent(object, eventType);
  294. objectHandleFunctions_[object].Erase(i);
  295. }
  296. }
  297. }
  298. void LuaScript::ScriptUnsubscribeFromEvent(void* sender, const String& eventName, const String& functionName)
  299. {
  300. WeakPtr<LuaFunction> function = GetFunction(functionName);
  301. if (!function)
  302. return;
  303. StringHash eventType(eventName);
  304. Object* object = (Object*)sender;
  305. HashMap<StringHash, LuaFunctionVector>::Iterator i = objectHandleFunctions_[object].Find(eventType);
  306. if (i != objectHandleFunctions_[object].End())
  307. {
  308. LuaFunctionVector& functions = i->second_;
  309. functions.Remove(function);
  310. if (functions.Empty())
  311. {
  312. UnsubscribeFromEvent(object, eventType);
  313. objectHandleFunctions_[object].Erase(i);
  314. }
  315. }
  316. }
  317. void LuaScript::ScriptUnsubscribeFromEvents(void* sender)
  318. {
  319. Object* object = (Object*)sender;
  320. HashMap<Object*, HashMap<StringHash, LuaFunctionVector> >::Iterator it = objectHandleFunctions_.Find(object);
  321. if (it == objectHandleFunctions_.End())
  322. return;
  323. UnsubscribeFromEvents(object);
  324. objectHandleFunctions_.Erase(it);
  325. }
  326. void LuaScript::SetExecuteConsoleCommands(bool enable)
  327. {
  328. if (enable == executeConsoleCommands_)
  329. return;
  330. executeConsoleCommands_ = enable;
  331. if (enable)
  332. SubscribeToEvent(E_CONSOLECOMMAND, HANDLER(LuaScript, HandleConsoleCommand));
  333. else
  334. UnsubscribeFromEvent(E_CONSOLECOMMAND);
  335. }
  336. void LuaScript::RegisterLoader()
  337. {
  338. // Get package.loaders table
  339. lua_getglobal(luaState_, "package");
  340. lua_getfield(luaState_, -1, "loaders");
  341. // Add LuaScript::Loader to the end of the table
  342. lua_pushinteger(luaState_, lua_objlen(luaState_, -1) + 1);
  343. lua_pushcfunction(luaState_, &LuaScript::Loader);
  344. lua_settable(luaState_, -3);
  345. lua_pop(luaState_, 2);
  346. }
  347. int LuaScript::AtPanic(lua_State* L)
  348. {
  349. String errorMessage = luaL_checkstring(L, -1);
  350. LOGERROR("Lua error: Error message = '" + errorMessage + "'");
  351. lua_pop(L, 1);
  352. return 0;
  353. }
  354. int LuaScript::Loader(lua_State* L)
  355. {
  356. ResourceCache* cache = ::GetContext(L)->GetSubsystem<ResourceCache>();
  357. // Get module name
  358. const char* name = luaL_checkstring(L, 1);
  359. // Attempt to get .luc file first.
  360. String lucFileName = String(name) + ".luc";
  361. LuaFile* lucFile = cache->GetResource<LuaFile>(lucFileName, false);
  362. if (lucFile)
  363. return lucFile->LoadChunk(L) ? 1 : 0;
  364. // Then try to get .lua file. If this also fails, error is logged and resource not found event is sent
  365. String luaFileName = String(name) + ".lua";
  366. LuaFile* luaFile = cache->GetResource<LuaFile>(luaFileName);
  367. if (luaFile)
  368. return luaFile->LoadChunk(L) ? 1 : 0;
  369. return 0;
  370. }
  371. void LuaScript::ReplacePrint()
  372. {
  373. static const struct luaL_reg reg[] =
  374. {
  375. {"print", &LuaScript::Print},
  376. { NULL, NULL}
  377. };
  378. lua_getglobal(luaState_, "_G");
  379. luaL_register(luaState_, NULL, reg);
  380. lua_pop(luaState_, 1);
  381. }
  382. int LuaScript::Print(lua_State *L)
  383. {
  384. String string;
  385. int n = lua_gettop(L);
  386. lua_getglobal(L, "tostring");
  387. for (int i = 1; i <= n; i++)
  388. {
  389. const char *s;
  390. // Function to be called
  391. lua_pushvalue(L, -1);
  392. // Value to print
  393. lua_pushvalue(L, i);
  394. lua_call(L, 1, 1);
  395. // Get result
  396. s = lua_tostring(L, -1);
  397. if (s == NULL)
  398. return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
  399. if (i > 1)
  400. string.Append(" ");
  401. string.Append(s);
  402. // Pop result
  403. lua_pop(L, 1);
  404. }
  405. LOGRAW(string + "\n");
  406. return 0;
  407. }
  408. WeakPtr<LuaFunction> LuaScript::GetFunction(int functionIndex)
  409. {
  410. if (!lua_isfunction(luaState_, functionIndex))
  411. return WeakPtr<LuaFunction>();
  412. const void* functionPointer = lua_topointer(luaState_, functionIndex);
  413. if (!functionPointer)
  414. return WeakPtr<LuaFunction>();
  415. HashMap<const void*, SharedPtr<LuaFunction> >::Iterator i = functionPointerToFunctionMap_.Find(functionPointer);
  416. if (i != functionPointerToFunctionMap_.End())
  417. return WeakPtr<LuaFunction>(i->second_);
  418. lua_pushvalue(luaState_, functionIndex);
  419. int functionRef = luaL_ref(luaState_, LUA_REGISTRYINDEX);
  420. SharedPtr<LuaFunction> function(new LuaFunction(luaState_, functionRef, false));
  421. functionPointerToFunctionMap_[functionPointer] = function;
  422. return WeakPtr<LuaFunction>(function);
  423. }
  424. WeakPtr<LuaFunction> LuaScript::GetFunction(const String& functionName, bool silentIfNotFound)
  425. {
  426. if (!luaState_)
  427. return WeakPtr<LuaFunction>();
  428. HashMap<String, SharedPtr<LuaFunction> >::Iterator i = functionNameToFunctionMap_.Find(functionName);
  429. if (i != functionNameToFunctionMap_.End())
  430. return WeakPtr<LuaFunction>(i->second_);
  431. int top = lua_gettop(luaState_);
  432. SharedPtr<LuaFunction> function;
  433. if (PushScriptFunction(functionName, silentIfNotFound))
  434. {
  435. int ref = luaL_ref(luaState_, LUA_REGISTRYINDEX);
  436. function = new LuaFunction(luaState_, ref);
  437. }
  438. lua_settop(luaState_, top);
  439. functionNameToFunctionMap_[functionName] = function;
  440. return WeakPtr<LuaFunction>(function);
  441. }
  442. void LuaScript::HandleEvent(StringHash eventType, VariantMap& eventData)
  443. {
  444. LuaFunctionVector& functions = eventHandleFunctions_[eventType];
  445. for (unsigned i = 0; i < functions.Size(); ++i)
  446. {
  447. WeakPtr<LuaFunction> function = functions[i];
  448. if (function && function->BeginCall())
  449. {
  450. function->PushUserType(eventType, "StringHash");
  451. function->PushUserType(eventData, "VariantMap");
  452. function->EndCall();
  453. }
  454. }
  455. }
  456. void LuaScript::HandleObjectEvent(StringHash eventType, VariantMap& eventData)
  457. {
  458. Object* object = GetEventSender();
  459. LuaFunctionVector& functions = objectHandleFunctions_[object][eventType];
  460. for (unsigned i = 0; i < functions.Size(); ++i)
  461. {
  462. WeakPtr<LuaFunction> function = functions[i];
  463. if (function && function->BeginCall())
  464. {
  465. function->PushUserType(eventType, "StringHash");
  466. function->PushUserType(eventData, "VariantMap");
  467. function->EndCall();
  468. }
  469. }
  470. }
  471. void LuaScript::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
  472. {
  473. // Call also user-subscribed PostUpdate handler (if any)
  474. HandleEvent(eventType, eventData);
  475. if (coroutineUpdate_ && coroutineUpdate_->BeginCall())
  476. {
  477. using namespace PostUpdate;
  478. float timeStep = eventData[P_TIMESTEP].GetFloat();
  479. coroutineUpdate_->PushFloat(timeStep);
  480. coroutineUpdate_->EndCall();
  481. }
  482. // Collect garbage
  483. {
  484. PROFILE(CollectLuaGarbage);
  485. lua_gc(luaState_, LUA_GCCOLLECT, 0);
  486. }
  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. }